bmlct / android-test-kit

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

ActivityInstrumentationTestCase2 with only JUnit 4 test cases not run by AndroidJUnitRunner #177

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Create a new test class  extending ActivityInstrumentationTestCase2
2. Add some standard JUnit style 3 tests
2. Follow all steps to convert to JUnit 4 
(https://code.google.com/p/android-test-kit/wiki/AndroidJUnitRunnerUserGuide)
2. Remove all 'test_' prefixes from the tests and use the @Test annotation 
instead
3. Run all tests in the Android module or via Gradle (./gradlew connectedAT 
--debug)

What is the expected output? What do you see instead?
Expected: all tests in the test class should be run
Actual: no tests are run at all. -> empty test suite

What version of the product are you using? On what operating system?
com.android.support.test:runner:0.3
gradle-2.4-all
Android studio 1.4 beta 2
Mac OSX 10.10

Please provide any additional information below.
When there is at least one JUnit style 3 test method with a 'test_' prefix in 
the class, all tests are run properly.
For example adding this method (public void test_beHereSoAllOtherTestsRun() { 
/* NOP */ }) causes all other tests to run properly.

Is it possible that the AndroidJUnitRunner expects at least one such method?

Note that running the Test class directly does work, it only doesn't work if 
you run all tests within the module. (via Android studio or directly via Gradle)

Full test class:
package com.jmolsmobile.landscapevideocapture;

import android.support.test.InstrumentationRegistry;
import android.support.test.runner.AndroidJUnit4;
import android.test.ActivityInstrumentationTestCase2;

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

import static org.hamcrest.core.IsNull.notNullValue;
import static org.junit.Assert.assertThat;

@RunWith(AndroidJUnit4.class)
public class VideoCaptureActivityTest extends 
ActivityInstrumentationTestCase2<VideoCaptureActivity> {

    public VideoCaptureActivityTest() {
        super(VideoCaptureActivity.class);
    }

    @Before
    public void setUp() throws Exception {
        super.setUp();
        injectInstrumentation(InstrumentationRegistry.getInstrumentation());
    }

    @Test
    public void checkPreconditions() {
        assertThat(getActivity(), notNullValue());
        // Check that Instrumentation was correctly injected in setUp()
        assertThat(getInstrumentation(), notNullValue());
    }

    @After
    public void tearDown() throws Exception {
        super.tearDown();
    }
}

Original issue reported on code.google.com by jeroen.m...@gmail.com on 1 Sep 2015 at 12:45

GoogleCodeExporter commented 9 years ago
The new ActivityTestRule works properly with JUnit4.

Full working example:
import android.support.test.rule.ActivityTestRule;
import android.support.test.runner.AndroidJUnit4;

import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;

import static org.hamcrest.core.IsNull.notNullValue;
import static org.junit.Assert.assertThat;

@RunWith(AndroidJUnit4.class)
public class VideoCaptureActivityTest {

    @Rule
    public ActivityTestRule<VideoCaptureActivity> mActivityRule = new ActivityTestRule<>(VideoCaptureActivity.class);

    @Test
    public void checkPreconditions() {
        assertThat(mActivityRule.getActivity(), notNullValue());
    }
}

Still I feel the documentation 
(https://code.google.com/p/android-test-kit/wiki/AndroidJUnitRunnerUserGuide) 
should be updated as this refers to a non working example.

Original comment by jeroen.m...@gmail.com on 1 Sep 2015 at 2:41

GoogleCodeExporter commented 9 years ago

Original comment by slinz...@google.com on 15 Sep 2015 at 10:58