是否可以从JUnit测试用例中逃脱(可能通过反射)并修改测试结果?
假设我们有一个方法
int foo() { ... }
正在测试和方法
void fooTest() { ... }
测试foo()
是否正确实施。
是否有可能在foo()
作弊并访问(可能通过堆栈跟踪和反射)测试方法/结果,这样即使foo
不正确,测试也不会失败? / p>
答案 0 :(得分:1)
@Ignore
用于暂时禁用测试:
@Ignore
@Test
public void testMethod() { // enter code here }
也可以提供可选的原因:
@Ignore("Under development")
@Test
public void testMethod() { // enter code here }
@Ignore
可以在班级使用:
@Ignore
public class IgnoreTestClass {
@Test public void testOne(){`enter code here`}
@Test public void testTwo(){`enter code here`}
}
答案 1 :(得分:0)
如果在另一个testcases
中创建了这些JUnit classes
,您可以在TestSuite
课程中运行这些JUnit class
。它可以调整TestSuite
中的灯芯{{1}}。