Monday 5 December 2016

Why Junit doesn't consider other classes as test class

I faced this tricky and very simple problem.
When I created a Maven Java project I got one default test class named "AppTest" and default method "testApp"

With JUnit 3.

Problem:
I created another test class in same package, named "AppTest2" and methods "testApp".
When I run mvn clean test.

It never pick up that class as "Test" class.

Answer :
Junit expect each Test class name to end with "Test", like "AppTest.class","App1Test.class" etc

So I changed the new class name to App1Test.class and it picked all test cases inside during maven build.

Note: I changed the project test cases as JUnit 4-style from JUnit 3-style.
i.e. My test classes no longer extends TestCase 
I annotate each method with @Test, hence my test method name can be anything it need not start with "test"

No comments:

Post a Comment