【问题标题】:How to skip test if a condition is failed Junit (Instrumentation) Testing Android如果条件失败,如何跳过测试 Junit (Instrumentation) 测试 Android
【发布时间】:2019-11-29 06:20:34
【问题描述】:

我正在为设备测试编写测试用例,其中我必须检查一些 Wifi、消息、相机和音频 API,但前提是设备具有该功能

例子:

@Test
public void testMessagingApi() throws Exception {
    ....some test method....
}

但只有当我的设备具备消息功能时,才应执行此测试方法

public boolean isCapable(String feature) {
     Check some property to test if the feature is supported
     return supported;
}

只有当 isCapable 返回 true 时才应该执行测试,否则应该忽略或跳过它

这样的测试类怎么写

请人帮忙

【问题讨论】:

  • 看看这里,@RunIf 应该满足你的需求stackoverflow.com/questions/1689242/…
  • 用 RuniF 测试 @RunIf(DatabaseIsConnected.class) public void addition_isCorrect() { assertEquals(4, 2 + 2); } 类 DatabaseIsConnected 实现 Checker { Override public boolean meet() { return false; } } 这里我故意返回 false 但仍然试运行它显示通过 谁能帮忙

标签: android junit4 test-runner android-junit androidjunitrunner


【解决方案1】:

如果将 2 + 2 更改为 1 + 1,它会失败吗? (不能在上面发表评论,没有足够的声誉;)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-06-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-07-12
    • 2016-05-27
    • 1970-01-01
    相关资源
    最近更新 更多