Android Studio "No Tests Were Found"


Answer :

Today I had the same problem with some Espresso tests and it was getting me crazy because everything seemed normal. Finally I discovered the problem was because the method annotated with @BeforeClass was throwing an exception. If something goes wrong in that method, the stacktrace of the exception is not shown in the Log window of the Run tab but in the Log window of the Android Monitor tab

If you want to reproduce the problem just add this to your testing class:

@BeforeClass public static void setupClass() {     throw new RuntimeException("Sorry dude, you won't find any test!"); } 

This can happen when the type of your run configuration is incorrect.

With me, this goes wrong when running an Espresso test which used to be a unit test. For some reason it still uses the Android JUnit test configuration when running this test. Manually creating an Android Instrumented Test solves the problem.


Just for posterity sakes, here's the solution that worked for me -

The error you're seeing happens if AS for some reason thinks that the test that you're about to run is a unit and not an instrumentation test. Often this error goes away buy just clicking on the package instead of the actual class.

Found at https://github.com/googlecodelabs/android-testing/issues/27#issuecomment-219074863

I just ran the tests by right clicking on the package name and choosing "Run 'Tests in {packageName}'" and it worked.


Comments

Popular posts from this blog

Are Regular VACUUM ANALYZE Still Recommended Under 9.1?

Can Feynman Diagrams Be Used To Represent Any Perturbation Theory?