可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
I have no idea how to test and I was following a tutorial.I am trying to run:
package name.company.sunshine.app.data; import android.test.AndroidTestCase; public class TestPractice extends AndroidTestCase { /* This gets run before every test. */ @Override protected void setUp() throws Exception { super.setUp(); } public void testThatDemonstratesAssertions() throws Throwable { int a = 5; int b = 3; int c = 5; int d = 10; assertEquals("X should be equal", a, c); assertTrue("Y should be true", d > a); assertFalse("Z should be false", a == b); if (b > d) { fail("XX should never happen"); } } @Override protected void tearDown() throws Exception { super.tearDown(); } }
but I get somewhere in the bottom left corner, in the console Test events were not received. What am I doing wrong ? Should I run something else ?
回答1:
When you run your test select the Android Test option.
The JUnit and Gradle options should not be used for this type of test.
回答2:
I am doing the course too and ended up with the same problem.
After an hour of tinkering I think I found the solution.
Don't try to run the the test cases from the whole package as they did in the video; you have to run it from a single class and choose the AndroidTest option. It does not work with the Gradle option.
See picture attached. 
回答3:
I was able to get past this problem after making two changes.
uncheck use in-process build in Settings -> Build Tools -> Compiler Source: https://code.google.com/p/android/issues/detail?id=172162
force Gradle to re-run all tasks by updating your run configurations. Add --rerun-tasks to the Script Parameters.
Source: https://www.bignerdranch.com/blog/triumph-android-studio-1-2-sneaks-in-full-testing-support/
回答4:
This solution is tested in android studio 1.5.1
If you have problem with tests in android studio because use in-process build disappeared, include the following:
<project-folder> |-- .idea |-- workspace.xml
Just add the following component at the very top, just inside the project tag:
<project version="4"> <component name="AndroidGradleBuildConfiguration"> <option name="USE_EXPERIMENTAL_FASTER_BUILD" value="false" /> </component> ... </project>
回答5:
just as Matt Accola sayd, if you already selected the gradle option and cant find that sub menu in his answer, u will need to go to run >> Edit Configuration... and then under the Gradle sub menu, delete the items (TestPractice & others if existed) and then re do the test by selecting the AnroidTest.