dacongy / android-test-kit

Automatically exported from code.google.com/p/android-test-kit
0 stars 0 forks source link

AndroidJUnitRunner doesn't run JUnit test with clear JUnit4 style #123

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. My buid.gradle looks like:
buildscript {
...
}
apply plugin: 'com.android.application'

repositories {
...
}

android {
    compileSdkVersion 21
    buildToolsVersion '21'

    defaultConfig {
        minSdkVersion 14
        targetSdkVersion 19

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

    packagingOptions {
    ...
    }

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_7
        targetCompatibility JavaVersion.VERSION_1_7
    }

    productFlavors {
    ...
    }

    buildTypes {
    ...
    }
}

dependencies {
    ...
    androidTestCompile ('com.android.support.test.espresso:espresso-core:2.0') {}
    androidTestCompile ('com.android.support.test:testing-support-lib:0.1') {}
}

2. I have created simple JUnit test class using clear JUnit4 syntax 
(DemoPrinciplesOfUnitTesting.java).
3. I started tests but my class was not added to test suite.
4. When I renamed method thisIsTheTestTwo() to test_thisIsTheTestTwo() (JUnit 3 
syntax) I have receved expected result.
4. I have received the same results by starting tests with "./gradlew 
connectedCheck" console command.

What is the expected output? What do you see instead?
Expected output:
V/DEMO﹕ Setup CLASS
V/DEMO﹕ Setup test
V/DEMO﹕ Perform test 2
V/DEMO﹕ Tear down test
V/DEMO﹕ Setup test
V/DEMO﹕ Perform test 1
V/DEMO﹕ Tear down test
V/DEMO﹕ Setup test
V/DEMO﹕ Perform test 3
V/DEMO﹕ Tear down test
V/DEMO﹕ Tear down CLASS

But I see instead:
nothing

What version of the product are you using? On what operating system?
Espresso 2.0
Android Studio 1.0.2
Gradle wrapper 2.2.1
OS Ubuntu 12.04 LTS x64

Please provide any additional information below.
My DemoPrinciplesOfUnitTesting.java

package ...

import android.support.test.runner.AndroidJUnit4;
import android.util.Log;

import junit.framework.TestCase;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.runner.RunWith;

@RunWith(AndroidJUnit4.class)
public class DemoPrinciplesOfUnitTesting extends TestCase {
    private static String DEMO_TAG = "DEMO";

    @BeforeClass
    public static void prepareClassForStartAllTests() {
        Log.v(DEMO_TAG, "Setup CLASS");
    }

    @Before
    public void doTestSetUp() throws Exception {
        super.setUp();
        Log.v(DEMO_TAG, "Setup test");
    }

    @After
    public void doTestTearDown() throws Exception {
        super.tearDown();
        Log.v(DEMO_TAG, "Tear down test");
    }

    @Test
    public void test_thisIsTheTestTwo() {
        Log.v(DEMO_TAG, "Perform test 2");
    }

    @Test
    public void thisIsTheTestOne() {
        Log.v(DEMO_TAG, "Perform test 1");
    }

    @Test
    public void thisIsTheTestThree() {
        Log.v(DEMO_TAG, "Perform test 3");
    }

    @AfterClass
    public static void clearAfterAllTests() throws Exception {
        Log.v(DEMO_TAG, "Tear down CLASS");
    }
}

Original issue reported on code.google.com by d.korabl...@mobidev.biz on 22 Jan 2015 at 1:35

GoogleCodeExporter commented 9 years ago
I am experiencing similar issues with classes extending 
ActivityInstrumentationTestCase2 (which itself extends TestCase). I can 
reproduce this in the simple project found here: 
https://github.com/commonsguy/cw-omnibus/tree/master/Testing/JUnit4

Interestingly, I have found that if I specify the specific test class or test 
method, then the tests run successfully.

Original comment by chris.va...@laterooms.com on 20 Feb 2015 at 5:43

GoogleCodeExporter commented 9 years ago

Original comment by vale...@google.com on 18 Mar 2015 at 5:18

GoogleCodeExporter commented 9 years ago
Are you running JUnit3 and JUnit4 tests at the same time? 

In that case, create a test suite as seen in 
https://github.com/googlesamples/android-testing/blob/master/testrunner/AndroidJ
unitRunnerSample/app/src/androidTest/java/com/example/android/testing/androidjun
itrunnersample/suite/AndroidTestSuite.java

Chris: is that project still having issues? I see updates since you sent your 
message.

Original comment by jalc@google.com on 20 Mar 2015 at 10:33

GoogleCodeExporter commented 9 years ago
Closing for now, re-open if it's still an issue.

Original comment by jalc@google.com on 1 Apr 2015 at 4:50