I have never used JUnit before, and now I'm trying to set it up on an Android project.
My project under test is fairly complex, including some JNI, but my test project, at the moment, is completely trivial. I have found many examples (that look totally different) online of how to make a test project, but it seems that no matter which one I follow, I get the same results.
Here's my JUnit project code:
package com.mycompany.myproject.test;
import android.test.AndroidTestCase;
public class SimpleTestCaseExample extends AndroidTestCase {
public void test_testOne() {
fail("Just Always Fail");
}
}
When I run, I see the following in Logcat:
stdout INSTRUMENTATION_STATUS: numtests=2 stdout INSTRUMENTATION_STATUS: test=test_testOne stdout INSTRUMENTATION_STATUS_CODE: 0 stdout INSTRUMENTATION_STATUS: id=InstrumentationTestRunner stdout INSTRUMENTATION_STATUS: current=2 stdout INSTRUMENTATION_STATUS: class=com.mycompany.myproject.test.SimpleTestCaseExample stdout INSTRUMENTATION_STATUS: stream= stdout INSTRUMENTATION_STATUS: numtests=2 stdout INSTRUMENTATION_STATUS: test=testAndroidTestCaseSetupProperly stdout INSTRUMENTATION_STATUS_CODE: 1 stdout INSTRUMENTATION_STATUS: id=InstrumentationTestRunner stdout INSTRUMENTATION_STATUS: current=2 stdout INSTRUMENTATION_STATUS: class=com.mycompany.myproject.test.SimpleTestCaseExample stdout INSTRUMENTATION_STATUS: stream=. stdout INSTRUMENTATION_STATUS: numtests=2 stdout INSTRUMENTATION_STATUS: test=testAndroidTestCaseSetupProperly stdout INSTRUMENTATION_STATUS_CODE: 0 stdout INSTRUMENTATION_RESULT: stream= stdout Test results for InstrumentationTestRunner=.. stdout Time: 0.07 stdout OK (2 tests) stdout INSTRUMENTATION_CODE: -1
But, I get the following in the Console:
Launching instrumentation android.test.InstrumentationTestRunner on device emulator-5554 Collecting test information Test run failed: No test results
I have tried a variety of different things, messing with the basic TestCase class, or the TestSuite class, or a variety of other options. I tried to just go for the most trivial example because I'm really still trying to learn how this works.
Whatever I try, I see this error.
Any suggestions would be appreciated!
If I'm missing some critical information, please let me know and I'll update.
OK, I figured it out.
And there is very little chance that anybody would have guessed what the problem is. I'm not sure what made me try it.
I have some JNI code that prints error messages to stdout. That code is not running in my test project, but I use the same emulator. For that reason, I had a /data/local.prop that redirects stdout to logcat.
It turns out that the test tools expect the output from the JUnit tests to appear on stdout. When the logcat redirect of stdout is on, nothing ends up on stdout, and the test system doesn't get the output, and so it fails to run.
I removed my local.prop redirect of stdout to logcat, and rebooted the emulator, and now it works.
It never occurred to me that the test system relied upon reading stdout itself.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With