testNG忽略测试
有时我们的代码没有准备好,如果测试用例写入到测试方法/代码将无法运行,在这种情况下,
@Test(enabled=false)有助于禁用此测试案例
测试方法是标注了@Test(enabled=false),那么并不是已经准备好测试的测试用例都绕过
创建一个Java类进行测试为MessageUtil.java
package hello;
/*
* This class prints the given message on console.
*/
public class MessageUtil {
private String message;
// Constructor
// @param message to be printed
public MessageUtil(String message) {
this.message = message;
}
// prints the message
public String printMessage() {
System.out.println(message);
return message;
}
// add "Hi!" to the message
public String salutationMessage() {
message = "Hi!" + message;
System.out.println(message);
return message;
}
}
创建测试方案
创建Java测试类为IgnoreTest.java
测试类添加测试方法testPrintMessage(),testSalutationMessage()
添加注释@Test(enabled= false)到方法testPrintMessage()
创建一个类
package hello;
/*
* This class prints the given message on console.
*/
public class MessageUtil {
private String message;
// Constructor
// @param message to be printed
public MessageUtil(String message) {
this.message = message;
}
// prints the message
public String printMessage() {
System.out.println(message);
return message;
}
// add "Hi!" to the message
public String salutationMessage() {
message = "Hi!" + message;
System.out.println(message);
return message;
}
}
创建测试方案
package hello;
import org.testng.annotations.Test;
import org.testng.Assert;
public class IgnoreTest {
String message = "Manisha";
MessageUtil messageUtil = new MessageUtil(message);
@Test(enabled=false)
public void testPrintMessage() {
System.out.println("Inside testPrintMessage()");
message = "Manisha";
Assert.assertEquals(message, messageUtil.printMessage());
}
@Test
public void testSalutationMessage(){
System.out.println("Inside testSalutationMessage()");
message = "Hi!"+"Manisha";
Assert.assertEquals(message, messageUtil.salutationMessage());
}
}
textng.xml
<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >
<suite name="Suite1">
<test name="test1">
<classes>
<class name="hello.IgnoreTest" />
</classes>
</test>
</suite>
测试结果
我们可以看到结果:没有运行第一个测试样例
---------------------
【转载,仅作分享,侵删】
作者:若海音符
来源:CSDN
原文:https://blog.csdn.net/Chenyt01/article/details/51752624
版权声明:本文为博主原创文章,转载请附上博文链接!
|
|