1

I upgraded my tests to junit5 now when I run my unit tests it also runs my instrumentation test which of course causes errors as they're not running in a simulator. How do I stop it from running them? I was able to solve some of the errors using @RunWith(AndroidJUnit4::class) but I still have one error and it’s driving me crazy

this is the error, however, I do not understand why my instrumentation tests are now running when I click on Run???

java.lang.NoClassDefFoundError: androidx/test/espresso/matcher/ViewMatchers

    at com.magtec.magtecmcc.MainActivityTest.testLaunch(MainActivityTest.kt:46)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
    at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
    at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
    at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
    at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
    at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:27)
    at androidx.test.rule.ActivityTestRule$ActivityStatement.evaluate(ActivityTestRule.java:531)
    at org.junit.rules.RunRules.evaluate(RunRules.java:20)
    at org.robolectric.internal.SandboxTestRunner$2.lambda$evaluate$0(SandboxTestRunner.java:256)
    at org.robolectric.internal.bytecode.Sandbox.lambda$runOnMainThread$0(Sandbox.java:89)
    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at java.lang.Thread.run(Thread.java:745)
Caused by: java.lang.ClassNotFoundException: androidx.test.espresso.matcher.ViewMatchers
    at org.robolectric.internal.bytecode.SandboxClassLoader.getByteCode(SandboxClassLoader.java:164)
    at org.robolectric.internal.bytecode.SandboxClassLoader.maybeInstrumentClass(SandboxClassLoader.java:119)
    at org.robolectric.internal.bytecode.SandboxClassLoader.lambda$findClass$0(SandboxClassLoader.java:112)
    at org.robolectric.util.PerfStatsCollector.measure(PerfStatsCollector.java:53)
    at org.robolectric.internal.bytecode.SandboxClassLoader.findClass(SandboxClassLoader.java:111)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    ... 19 more
1
  • You should be able to stop tests from being run with @Ignore annotation Commented Mar 27, 2019 at 22:10

1 Answer 1

0

multiple options first individually for tests:

  • @Ignore if you want to completely disable
  • put assumeTrue(condition); to deactivate a test on runtime conditions

  • and then you can also do this: start the test first then click on the dropdown menu at the top that displays your run configuration click on Edit Configurations

    • change the folder of the configuration to one that excludes your specific tests
    • or switch test kind to pattern and hope you have some kind of naming convention for the excluding testfiles then you can write a regex pattern that only includes the ones you want
Sign up to request clarification or add additional context in comments.

3 Comments

Great answer :) as for the last one I already have it set to the test folder only (yet it's still running the android test folder???) as you can see here imgur.com/a/lbolJ6N
Id recommend going with the pattern filter then and excluding every Test that contains "Instrumented" also maybe it helps setting some random weird sesttings to see if changes take effect
So I noticed that if I did clear cache (then it would run only the folder, finally) I found this stackoverflow.com/questions/51832349/… Seemed to work.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.