简体   繁体   中英

Strange junit4 behaviour with gradle

I'm trying to implement junit4 tests with gradle. So I have next build.gradle structure for my subproject:

buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:0.9.+'
    }
}
apply plugin: 'android'

android {

    defaultConfig {
        ...

        testPackageName "com.projectname.test"
    }

    packagingOptions {
        exclude 'LICENSE.txt'
    }

    ...

}

dependencies {
    ...

    androidTestCompile 'junit:junit:4.11'
}

I have src/androidTest/java dir with my sources for tests.

I have class where I write test method with junit4-style (annotations).

public class JustTest {

    @Test
    public void testExample() throws Exception {
        assertEquals(1, 1);
    }
}

And gradle says me that he doesn't see any test methods. But if I write test code in junit3-style all will work properly.

public class JustTest extends TestCase {

    public void testExample() throws Exception {
        assertEquals(1, 1);
    }
}

So what's wrong?

From http://developer.android.com/tools/testing/testing_android.html :

Note that the Android testing API supports JUnit 3 code style, but not JUnit 4.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM