运行单元测试时运行的Junit5和Instrumentation测试

Crash1hd

现在,当我运行单元测试时,我已将测试升级到junit5,它也运行了仪器测试,这当然会导致错误,因为它们不在模拟器中运行。如何停止运行它们?我可以使用@RunWith(AndroidJUnit4 :: class)解决一些错误,但仍然有一个错误,这让我发疯

这是错误,但是,当我单击“运行”时,我不理解为什么现在正在运行仪器测试???

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
乔纳森·海德尔

首先分别进行多个选项进行测试:

  • @忽略是否要完全禁用
  • 放假设为真(条件); 在运行时条件下停用测试

  • 然后您也可以执行以下操作:首先开始测试,然后单击显示您的运行配置的顶部下拉菜单,然后单击“编辑配置”。

    • 将配置文件夹更改为不包含特定测试的文件夹
    • 或将测试类型切换为模式,并希望您对排除的测试文件有某种命名约定,那么您可以编写一个仅包含所需的正则表达式模式

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

JUnit5IdeaTestRunner无法运行单元测试

Maven不会运行JUnit5测试

JUnit Eclipse无法运行单元测试

使用@Configuration时运行单元测试时出现NoSuchBeanDefinitionException

单元测试断言失败时运行代码

JUnit4和JUnit5测试未在IntelliJ中运行

无法运行测试类“未找到测试运行程序‘Junit5’的测试”

测试未按JUnit5中的指定顺序运行

如何运行基于 JUnit5 的测试套件?

单元测试未运行

单元测试未运行

运行Tensorflow单元测试

IntelliJ使用Maven而不是JUnit运行单元测试

如何配置Maven插件以运行Spock和Junit5测试

在Maven CLI中同时运行Cucumber和JUnit测试

如何使用SpringBoot2,JUnit5和Kotlin将配置属性注入到单元测试中

只想在运行单元测试时运行自定义gradle任务

在使用 Junit5 的 spock 单元测试中不考虑 @Rule 注释

是否可以将pom.xml设置为从命令行分别运行testNG(UI性能测试)测试和jUnit(单元测试)测试?

Jenkins和Sonarqube-在哪里运行单元测试

单元测试和运行时的不同代码行为

使用* ngFor和Input运行单元测试

在Visual Studio的子类中继承和运行单元测试

未通过测试运行器JUnit5找到测试

并行运行JUnit5测试,但要离开一些测试顺序

使用django-webpack-loader时运行单元测试而不产生资产

单元测试期间何时运行单例析构函数

装饰一个python函数以在模块为主时运行单元测试

PyCharm-每次保存文件时运行相应的单元测试