【问题标题】:How to write a failing test in this case?在这种情况下如何编写失败的测试?
【发布时间】:2016-12-17 21:55:54
【问题描述】:

我想在 intellij 中使用 evosuite 测试一些简单的程序,并且我希望一些测试失败。我是用 evosuite 生成的测试并构建了 test_cases。但是当我用junit测试它们之后,它们都通过了!

我怎样才能让程序中的某些测试失败? 这是我添加“while(true)”错误的简单程序:

While(true) 
      int a=8;
      int b=2;
      a=b; 

【问题讨论】:

    标签: unit-testing testing intellij-idea junit evosuite


    【解决方案1】:

    使用断言、abort() 方法,并根据需要抛出异常。

    想象一下你有一个预期返回 2 的方法。 以下是如何测试它:

    int a = yourmethod();
    Assert.assertEquals(2, a);
    

    如果应该满足某个条件:

    if (condition) {
    // Check something else
    } else {
    abort() // this method fails the test
    }
    

    【讨论】:

    • 其实我对测试和evosuite知之甚少。但我必须这样做,那太紧急了......你能解释一下吗????并编辑我的简单代码,例如......非常感谢
    • اگه فارسی توضیح بدید هم مشکلی نیس.هر جور راحت هستید
    • har koja az 方法 e 测试年龄异常 rokh bede un test fail mishe。 ye rahe dg ke dar sharayeti ke mikhayn yek test ro 失败 konid ine ke az 方法 e abort() estefade konid (masalan dakhele ye if ke age bargharar nabashe test bayad fail she)。断言 ha ham sharayete dakhele yek 测试 ro 检查 mikonan va 年龄 bargharar nabashe uno 未通过 mikonan。 masalan assretEquals() do ta argument migire ke yekish javabie ke entezar darid va yekish javabie ke barname be shoma mide va age in 2 ta mosavi nabashan un test ro fail mikone.
    猜你喜欢
    • 2021-11-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-05-21
    • 2013-11-03
    • 2012-01-31
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多