Search code examples
javaunit-testingjunit5junit-jupiter

ParameterizedTest gets executed before @Before function


why parameterized tests are executed before setUp function?

    @Before
    public void setUp(){
        System.out.println("some logic");
    }


    @ParameterizedTest
    @CsvSource({"1997"})
    void myTest(String arg) {
        System.out.println(arg);
    }

Solution

  • Relating to @aeberhart's comment, there is no @Before annotation in JUnit 5, if that's what you're using as a test runner. You need to use @BeforeAll, which in is the same as JUnit 4's @BeforeClass.