Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AndroidJUnit4 Instrumentation Tests fail to run #588

Closed
kingargyle opened this issue Feb 19, 2015 · 7 comments
Closed

AndroidJUnit4 Instrumentation Tests fail to run #588

kingargyle opened this issue Feb 19, 2015 · 7 comments

Comments

@kingargyle
Copy link

Trying to use the gist https://gist.github.com/JakeWharton/1c2f2cadab2ddd97f9fb to get Instrumentation Tests to run without needing to extend the InstrumentationTestCase or their sub classes.

If I just create a test case like:

@SuppressLint("NewApi")
@RunWith(AndroidJUnit4.class)
public class LoginTest {

 @Rule
 ActivityRule activityRule = new ActivityRule(LoginActivity.class);

LoginActivity loginActivity;

@Before
public void setUp() throws Exception {
    loginActivity = (LoginActivity) activityRule.get();
}

@Test
public void checkPreconditions() {
    assertThat(loginActivity).isNotNull();
    assertThat(getInstrumentation()).isNotNull();
}

@After
public void tearDown() throws Exception {

}

}

The test never runs, and the integration-test never tries to kick off the test on the emulator. I can get a little farther with the following:

@SuppressLint("NewApi")
@RunWith(AndroidJUnit4.class)
public class LoginTest extends InstrumentationTestCase {

@Rule
ActivityRule activityRule = new ActivityRule(LoginActivity.class);

LoginActivity loginActivity;

@Before
public void setUp() throws Exception {
    super.setUp();
    loginActivity = (LoginActivity) activityRule.get();
}

@Test
public void checkPreconditions() {
    assertThat(loginActivity).isNotNull();
    assertThat(getInstrumentation()).isNotNull();
}

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

}

However, in this case it launches, deployes the instrumentation package, and then returns the following:

 emulator-5554_Nexus_7_unknown_AndroidSDKbuiltforx86_64 :   Running tests for specified test classes/methods: [com.altair.smartfusion.android.tests.LoginTest]
 [INFO] emulator-5554_Nexus_7_unknown_AndroidSDKbuiltforx86_64 :   Running instrumentation tests in com.altair.smartfusion.android.tests
 [INFO] emulator-5554_Nexus_7_unknown_AndroidSDKbuiltforx86_64 :     Run started: com.altair.smartfusion.android.tests, 0 tests:
[INFO] emulator-5554_Nexus_7_unknown_AndroidSDKbuiltforx86_64 :     Run ended: 0 ms
[INFO]   Tests run: 0,  Failures: 0,  Errors: 0,  Ignored: 0
[INFO] emulator-5554_Nexus_7_unknown_AndroidSDKbuiltforx86_64 :   Report file written to /Users/davidcarver/Work/IQ/git/fusion-android/integration-tests/target/surefire-reports/TEST-emulator-5554_Nexus_7_unknown_AndroidSDKbuiltforx86_64.xml

So it acts like it never runs the tests at all. If I switch to a regular JUnit 3 test case, it works, but I'd rather use the goodness that the new AndroidJunit4 runner provides as documented here:

https://code.google.com/p/android-test-kit/wiki/AndroidJUnitRunnerUserGuide

Even if I specify the class to run, it won't do it.

My AndroidManfest.xml looks like the following:

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
  package="com.example.test"
  android:versionCode="1"
  android:versionName="0.0.0" >

<uses-sdk
    android:minSdkVersion="16"
    android:targetSdkVersion="19" />

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

<application>
    <uses-library android:name="android.test.runner" />
</application>

<instrumentation
        android:name="android.support.test.runner.AndroidJUnitRunner"
        android:label="Example Test"
        android:targetPackage="com.example" />

</manifest>
@athkalia
Copy link
Contributor

athkalia commented Mar 4, 2015

try adding a

<configuration>
<testSkip>false</testSkip>
</configuration>

in your android maven plugin pom.xml

@kingargyle
Copy link
Author

The tests being skipped isn't the issue, it just doesn't seem to be recognized on the emulator or device that they are instrumentation tests. I'm seeing similar issues when trying to run from an IDE so I need to do some more research on it when I get time.

@athkalia
Copy link
Contributor

athkalia commented Mar 4, 2015

According to testSkip javadoc:

Enables or disables integration test related goals. If <code>true</code> they will be skipped; if
<code>false</code>, they will be run. If <code>auto</code>, they will run if any of the classes inherit from any class in <code>junit.framework.</code> or <code>android.test.</code>.

I am guessing the default value is auto ?

Edit: Nevermind. If you figure this one out, can you please post the answer here

@secondsun
Copy link
Contributor

Will this fix your issue if it is implemented? #623

@kingargyle
Copy link
Author

Yes, I believe if #623 is implemented it should fix this issue.

@secondsun
Copy link
Contributor

@kingargyle #623 is implemented and shipped. Did it fix your issue/allow your issue to be fixed?

I'm using it in my project and it works well.

@kingargyle
Copy link
Author

Haven't tried it, probably won't get to check this out for a while, so I'm going to go ahead and close this issues since #623 is completed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants