I have inherited a Java project and am new to Java development. I feel a good way for me to get comfortable with the code is to write some tests around it. I\'m writing my c
In my case, I needed junit4-version.jar
in the classpath of the task junit and also:
ant-version.jar
ant-junit-version.jar
ant-junit4-version.jar
at the library of my ant installation (/usr/share/ant/lib
).
I was getting the error "junit.framework.AssertionFailedError: No tests found in ..." while I hadn't had ant-junit4-*version*.jar
in the right place.
I corrected this by installing ant-optional debian/ubuntu package:
apt-get install ant-optional
I had it when using data provider and one of the parameters had a new line character, like this:
@DataProvider
public static Object[][] invalidAdjustment() {
return new Object[][]{
{"some \n text", false},
};
}
Removing the \n
solved the issue
I had the same issue, in Intellij IDEA, for Java framework. I was doing all right:
But I did one thing wrong: the name of the method didn't start with "test", in fact was:
@Test
public void getSomethingTest(){
and when I changed it into:
@Test
public void testGetSomethingTest(){
I've resolved: the executor was finally able to recognize this method as a test method. I've changed nothing else.
I was fretting with this and none of the answers helped me until i moved the test source file from this folder:
src/test/java/com/junit/test
up to this folder:
src/test/java/com/junit
Extending junit.framework.TestCase
is the old JUnit 3 approach of implementing test cases which doesnt work as no methods start with the letters test. Since you're using JUnit 4, just declare the class as
public class EmailProviderTest {
and the test method will be found from the @Test
annotation.
Read: JUnit confusion: use 'extend Testcase' or '@Test'?
The other reason generally i see people having method parameters, remove any parameters you might have in the test method, regardless you add @Test annotation , you need to have your method name starting "test" in order for Junit to pick you testcase. hope it helps.