有时,我们的代码是没有准备好,如果测试用例写入到测试方法/代码将无法运行,在这种情况下,@Test(enabled = false)有助于禁用此测试案例。

测试方法是标注了@Test(enabled = false),那么并不是已经准备好测试的测试用例是绕过。

现在,让我们来看看测试@Test(enabled = false) 动作。

创建一个类

  • 创建一个Java类进行测试为 MessageUtil.java 在 C:\ > TestNG_WORKSPACE

/*
* 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().

创建一个Java类文件名 IgnoreTest.java 在 C:\ > TestNG_WORKSPACE

import org.testng.Assert;
import org.testng.annotations.Test; 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());
}
}

创建 testng.xml

创建一个文件 testng.xml C:\ > TestNG_WORKSPACE 用来执行测试案例

<?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="IgnoreTest" />
</classes>
</test>
</suite>

编译MessageUtil的测试用例类使用javac。

C:\TestNG_WORKSPACE>javac MessageUtil.java IgnoreTest.java

现在,运行testng.xml,将无法运行testPrintMessage()定义的测试用例在测试案例类。

C:\TestNG_WORKSPACE>java -cp "C:\TestNG_WORKSPACE" org.testng.TestNG testng.xml

验证输出。 testPrintMessage()测试用例没有测试。

Inside testSalutationMessage()
Hi!Manisha ===============================================
Suite1
Total tests run: 1, Failures: 0, Skips: 0
===============================================

也可以忽略一组测试将在下一章中讨论

文章转载自:易百教程 [http://www.yiibai.com]
本文标题:TestNG忽略测试
转载请保留原文链接:http://www.yiibai.com/html/testng/2013/0915299.html

testng入门教程6 TestNG忽略测试的更多相关文章

  1. testng入门教程12 TestNG执行多线程测试

    testng入门教程 TestNG执行多线程测试 testng入门教程 TestNG执行多线程测试 并行(多线程)技术在软件术语里被定义为软件.操作系统或者程序可以并行地执行另外一段程序中多个部分或者 ...

  2. testng入门教程7 TestNG组测试

    在TestNG中组测试是一个新的创新功能,它不存在于JUnit框架,它允许调度到适当的部分方法和瓶坯复杂的测试方法分组.您不仅可以声明属于群体的那些方法,但你也可以指定一组包含其他组.然后,TestN ...

  3. testng入门教程10 TestNG参数化测试

    在TestNG的另一个有趣的功能是参数测试.在大多数情况下,你会遇到这样一个场景,业务逻辑需要一个巨大的不同数量的测试.参数测试,允许开发人员运行同样的测试,一遍又一遍使用不同的值. TestNG让你 ...

  4. testng入门教程9 TestNG依赖测试

    有时候,你可能需要在一个特定的顺序调用方法在测试案例,或你想分享一些数据和方法之间的状态.TestNG支持这种依赖测试方法之间的显式依赖它支持声明. TestNG允许指定依赖,无论与否: 使用属性de ...

  5. testng入门教程8 TestNG异常测试

    TestNG跟踪异常处理代码提供了一个选项.可以测试是否需要代码抛出异常或不抛出. @Test注释expectedExceptions 参数一起使用.现在,让我们来看看@Test(expectedEx ...

  6. testng入门教程11 TestNG运行JUnit测试

    现在,您已经了解了TestNG和它的各种测试,如果现在担心如何重构现有的JUnit代码,那就没有必要,使用TestNG提供了一种方法,从JUnit和TestNG按照自己的节奏.也可以使用TestNG执 ...

  7. TestNG 入门教程【转】

    TestNG 入门教程[转] 国庆7天假期,大部分朋友都出去旅游了,微信圈里全是晒旅游的照片, 东南亚游,欧洲游呀,真是羡慕呀. 悲惨的我只去了上海野生动物园, 在家休息,利用这段假期,把之前学过的东 ...

  8. testng入门教程16数据驱动(把数据写在xml)

    testng入门教程16数据驱动(把数据写在xml) testng入门教程16数据驱动(把数据写在xml)把数据写在xml文件里面,在xml文件右键选择runas---testng执行 下面是case ...

  9. testng入门教程5TestNG套件测试

    TestNG套件测试 测试套件的测试是为了测试软件程序的行为或一系列行为的情况下,是一个集合.在TestNG,我们不能定义一套测试源代码,但它代表的套件是一个XML文件执行特征.这也允许灵活的配置要运 ...

随机推荐

  1. webpack4 优化记录

    webpack4.0优化那些事儿 一 缩小文件搜索范围 1 include & exclude 1) action 限制编译范围 2) useage module: { rules: [ { ...

  2. C#生成随机验证码例子

    C#生成随机验证码例子: 前端: <tr> <td width=" align="center" valign="top"> ...

  3. css3整理--gradient

    gradient语法: -moz-linear-gradient( [<point> || <angle>,]? <stop>, <stop> [, & ...

  4. 解决Devexpress ChartControl的CalcHitInfo当中SeriesPoint为Null的问题

    Winform程序 ChartControl的RuntimeHitTesting属性一定要设为True. Line Series markers的Visible一定要弄成True.CalcHitInf ...

  5. 题目1099:后缀子串排序(qsort函数自定义cmp函数)

    题目链接:http://ac.jobdu.com/problem.php?pid=1099 详解链接:https://github.com/zpfbuaa/JobduInCPlusPlus 参考代码: ...

  6. java.lang.NoClassDefFoundError: Could not initialize class xxx 原因

    一.问题及原因 程序里有个工具类,主要是调用它的静态方法来发送mq. 调用场景如下: 结果这两天报了个错: java.lang.NoClassDefFoundError: Could not init ...

  7. ftp主动与被动模式详解

    FTP是仅基于TCP的服务,不支持UDP.与众不同的是FTP使用2个端口,一个数据端口和一个命令端口(也可叫做控制端口).通常来说这两个端口是21(命令端口)和20(数据端口).但FTP工作方式的不同 ...

  8. 供安全工程师实用的SOC模型

    一.背景 如今,安全概念满天飞,什么安全运营中心(SOC).威胁情报(TI).态势感知等等不一而足,这些概念及其背后代表的安全思想都很好,不过很多产品为了迎合国内的工作汇报都做成了很多Dashboar ...

  9. 熟悉使用ConfigParser库读写配置文件

    Python的配置文件 配置文件 setting.ini文件是一个纯文本 [DataBase1] username = admin passwors = root [DataBase2] hostna ...

  10. MacOS 安装 nginx

    brew install nginx 开机启动 $ sudo cp `brew --prefix nginx`/homebrew.mxcl.nginx.plist /Library/LaunchDae ...