Anton Holovin
Anton Holovin

Reputation: 5673

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?

Upvotes: 0

Views: 93

Answers (1)

Peter Niederwieser
Peter Niederwieser

Reputation: 123910

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.

Upvotes: 1

Related Questions