Test events were not received - Android Studio

匿名 (未验证) 提交于 2019-12-03 02:23:02

问题:

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.



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!