No tests found for given includes Error, when running Parameterized Unit test in Android Studio

前端 未结 17 1995
孤独总比滥情好
孤独总比滥情好 2021-01-31 07:03

I tried run Parameterized Unit Test as below in Android Studio.

import android.test.suitebuilder.annotation.SmallTest;  

import junit.framework.TestCase;    

i         


        
相关标签:
17条回答
  • 2021-01-31 07:11

    I was also facing the same problem. In My case, I am using JUnit 5 with gradle 6.6. I am managing integration test-cases in a separate folder call integ. I have to define a new task in build.gradle file and after adding first line -> useJUnitPlatform() , My problem got solved

    0 讨论(0)
  • 2021-01-31 07:13

    I made the mistake of defining my test like this

    class MyTest {
        @Test
        fun `test name`() = runBlocking {
    
    
            // something here that isn't Unit
        }
    }
    

    That resulted in runBlocking returning something, which meant that the method wasn't void and junit didn't recognize it as a test. That was pretty lame. I explicitly supply a type parameter now to run blocking. It won't stop the pain or get me my two hours back but it will make sure this doesn't happen again.

    class MyTest {
        @Test
        fun `test name`() = runBlocking<Unit> { // Specify Unit
    
    
            // something here that isn't Unit
        }
    }
    
    0 讨论(0)
  • 2021-01-31 07:15

    To add to already great and easy solution provided by Przemek315, the same config if you use Kotlin DSL:

    tasks.test {
        useJUnitPlatform()
    }
    
    0 讨论(0)
  • 2021-01-31 07:15

    If you are using intellij and want to use gradle you need to add this to the dependencies section of build.gradle file:

    testImplementation("org.junit.jupiter:junit-jupiter-api:5.4.2")
    testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:5.4.2")
    
    0 讨论(0)
  • 2021-01-31 07:19

    Steps:

    1. Add platform runner in build.gralde
      => testCompile group: 'org.junit.platform', name: 'junit-platform-runner', version: '1.7.0'
    2. Anotate test class with @RunWith => @RunWith(JunitPlatform.class)
    0 讨论(0)
  • 2021-01-31 07:22

    For me it worked when I've added @EnableJUnit4MigrationSupport class annotation.

    (Of course together with already mentioned gradle libs and settings)

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