cegonse/cest

Support parameterized test cases

jorsanpe opened this issue · 0 comments

This functionality is a bit advanced but quite useful because it allows reusing test cases and apply them to different input data. There is a very good example using the JUnitParamsRunner at https://github.com/sandromancuso/roman-numerals-kata/blob/master/src/test/java/com/codurance/RomanNumeralConverterShould.java:

    @Test
    @Parameters({
            "1, I",
            "2, II",
            "3, III",
            "4, IV",
            "5, V",
            "7, VII",
            "9, IX",
            "10, X",
            "17, XVII",
            "30, XXX",
            "38, XXXVIII",

            "479, CDLXXIX",
            "3999, MMMCMXCIX"
    }) public void
    convert_arabic_numbers_into_their_respective_roman_numeral(int arabic, String roman) {
        assertThat(romanFor(arabic), is(roman));
    }

I'm not sure about the right syntax, but maybe something like:

describe("Test with mocks", []() {
    withParameters(Parameter(1), Parameter(2))
    .it("runs the test with each parameter instance", [](Parameter value) {
    });
});

In the above example, the test would run twice, one for each instance of the parameter value. Notice the starting dot before the it.

There is an implementation of parameterized test cases (with constraints) in googletest.