Create multiple parameter sets in one parameterized class (junit)

后端 未结 8 926
无人共我
无人共我 2021-01-30 13:05

Currently I have to create a parameterized test class for every method that I want to test with several different inputs. Is there a way to add this together in one file?

<
8条回答
  •  -上瘾入骨i
    2021-01-30 13:07

    you can use parameters with https://github.com/piotrturski/zohhak:

    @TestWith({
       "1, 7, 8",
       "2, 9, 11"
    })
    public void addTest(int number1, int number2, int expectedResult) {
        BigDecimal result = calculator.add(number1, number2);
        assertThat(result).isEqualTo...
    }
    

    if you want to load parameters from file, you can use http://code.google.com/p/fuzztester/ or http://code.google.com/p/junitparams/

    and if you need real flexibility you can use junit's @Parameterized but it clutters your code. you can also use junit's Theories - but it seems an overkill for calculator tests

提交回复
热议问题