junit: no tests found

后端 未结 11 853
情书的邮戳
情书的邮戳 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 06:06

    I was getting this too:

    junit.framework.AssertionFailedError: No tests found in ...

    Solved by renaming the test method from method1

    @Test
    public void method1(){
        // Do some stuff...
    }
    

    to testMethod1

    @Test
    public void testMethod1(){
        // Do some stuff...
    }
    
    0 讨论(0)
  • 2020-12-14 06:06

    Test method name public void testName() {}

    Where name() in source naming name methods.

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

    I was getting this error, too:

    junit.framework.AssertionFailedError: No tests found in ...

    The reason was that I forgot to specify

    defaultConfig {
        ...
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    

    After syncing the project, it found the tests. So maybe it helps someone else.

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

    I bumped into the situation in JUnit 5 when created a private method:

    import org.junit.jupiter.api.Test
    
    class Test1 {
    
        @Test
        private fun sort() {
            println("1")
        }
    }
    

    Remove private.

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

    if you are using jUnit 4 then not use extends TestCase, removing this fixed error.

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