junit: no tests found

后端 未结 11 852
情书的邮戳
情书的邮戳 2020-12-14 05:47

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

相关标签:
11条回答
  • 2020-12-14 05:54

    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
    
    0 讨论(0)
  • 2020-12-14 05:55

    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

    0 讨论(0)
  • 2020-12-14 05:57

    I had the same issue, in Intellij IDEA, for Java framework. I was doing all right:

    • the class inherited from TestCase
    • I've imported junit.framework.TestCase
    • I've add the decoration @Test

    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.

    0 讨论(0)
  • 2020-12-14 06:00

    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
    
    0 讨论(0)
  • 2020-12-14 06:02

    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'?

    0 讨论(0)
  • 2020-12-14 06:03

    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.

    0 讨论(0)
提交回复
热议问题