NetBeans 7.2引入了TestNG
NetBeans 7.2的“新建文件”向导使创建空的TestNG测试用例更加容易。 以下屏幕快照展示了这一点,该屏幕快照是使用“新建文件” |“开始”按钮启动的。 单元测试(请注意,在“文件”下拉菜单下或通过在“项目”窗口中单击鼠标右键可以使用“新文件”)。
如上所示运行TestNG测试用例创建将导致以下生成的测试代码。
TestNGDemo.java(由NetBeans 7.2生成)
package dustin.examples;import org.testng.annotations.AfterMethod;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
import org.testng.Assert;/**** @author Dustin*/
public class TestNGDemo
{ public TestNGDemo(){}@BeforeClasspublic void setUpClass(){}@AfterClasspublic void tearDownClass(){}@BeforeMethodpublic void setUp(){}@AfterMethodpublic void tearDown(){}// TODO add test methods here.// The methods must be annotated with annotation @Test. For example://// @Test// public void hello() {}
}
NetBeans 7.2生成的测试包含注释,这些注释指示如何添加和注释测试方法(类似于现代版本的JUnit)。 生成的代码还显示了一些注释,用于整体测试用例的设置和拆卸以及针对每次测试的设置和拆卸(注释与JUnit相似)。 NetBeans标识此时尚未使用的import语句( import org.testng.annotations.Test;
和import org.testng.Assert;
),但是可能被使用,因此已包含在生成的代码中。
我可以轻松地将测试方法添加到此生成的测试用例中。 以下代码段是使用TestNG的测试方法。
testIntegerArithmeticMultiplyIntegers()
@Testpublic void testIntegerArithmeticMultiplyIntegers(){final IntegerArithmetic instance = new IntegerArithmetic();final int[] integers = {4, 5, 6};final int expectedProduct = 2 * 3 * 4 * 5 * 6;final int product = instance.multiplyIntegers(2, 3, integers);assertEquals(product, expectedProduct);}
当然,这看起来与我在测试Invalidgerquals with JUnit and Hamcrest和JUnit的内置Hamcrest Core Matcher Support文章中的插图所使用的IntegerArithmetic
类所使用的同一个IntegerArithmetic
类中使用的JUnit类似。 以下屏幕快照显示了通过右键单击测试用例类并选择“运行文件”(Shift + F6),在NetBeans 7.2 beta中的输出。
接下来,将复制NetBeans 7.2 beta中提供的TestNG运行的文本输出。
[TestNG] Running:Command line suite[VerboseTestNG] RUNNING: Suite: "Command line test" containing "1" Tests (config: null)
[VerboseTestNG] INVOKING CONFIGURATION: "Command line test" - @BeforeClass dustin.examples.TestNGDemo.setUpClass()
[VerboseTestNG] PASSED CONFIGURATION: "Command line test" - @BeforeClass dustin.examples.TestNGDemo.setUpClass() finished in 33 ms
[VerboseTestNG] INVOKING CONFIGURATION: "Command line test" - @BeforeMethod dustin.examples.TestNGDemo.setUp()
[VerboseTestNG] PASSED CONFIGURATION: "Command line test" - @BeforeMethod dustin.examples.TestNGDemo.setUp() finished in 2 ms
[VerboseTestNG] INVOKING: "Command line test" - dustin.examples.TestNGDemo.testIntegerArithmeticMultiplyIntegers()
[VerboseTestNG] PASSED: "Command line test" - dustin.examples.TestNGDemo.testIntegerArithmeticMultiplyIntegers() finished in 12 ms
[VerboseTestNG] INVOKING CONFIGURATION: "Command line test" - @AfterMethod dustin.examples.TestNGDemo.tearDown()
[VerboseTestNG] PASSED CONFIGURATION: "Command line test" - @AfterMethod dustin.examples.TestNGDemo.tearDown() finished in 1 ms
[VerboseTestNG] INVOKING CONFIGURATION: "Command line test" - @AfterClass dustin.examples.TestNGDemo.tearDownClass()
[VerboseTestNG] PASSED CONFIGURATION: "Command line test" - @AfterClass dustin.examples.TestNGDemo.tearDownClass() finished in 1 ms
[VerboseTestNG]
[VerboseTestNG] ===============================================
[VerboseTestNG] Command line test
[VerboseTestNG] Tests run: 1, Failures: 0, Skips: 0
[VerboseTestNG] ==============================================================================================
Command line suite
Total tests run: 1, Failures: 0, Skips: 0
===============================================Deleting directory C:\Users\Dustin\AppData\Local\Temp\dustin.examples.TestNGDemo
test:
BUILD SUCCESSFUL (total time: 2 seconds)
上面的示例显示了开始使用TestNG是多么容易,特别是如果从JUnit迁移到TestNG并正在使用NetBeans 7.2 beta。 当然,还有更给TestNG的不是这个,而是学习一个新的框架通常是最困难的,在开始和NetBeans 7.2得到一个开了一个快速启动。
参考: NetBeans 7.2在Inspired by Actual Events博客中从JCG合作伙伴 Dustin Marx 引入了TestNG 。
翻译自: https://www.javacodegeeks.com/2012/06/netbeans-72-introduces-testng.html
NetBeans 7.2引入了TestNG相关推荐
- netbeans7.4_NetBeans 7.2引入了TestNG
netbeans7.4 代码生成的优点之一是能够查看如何使用特定的语言功能或框架. 正如我在< NetBeans 7.2 beta:更快,更有用>一文中所讨论的那样, NetBeans 7 ...
- netbeans代码提示_Java代码现代化的七个NetBeans提示
netbeans代码提示 在" 七个不可或缺的NetBeans Java提示"一文中 ,我谈到了一般使用NetBeans提示的问题,然后重点介绍了七个提示. 接下来列出了该帖子中强 ...
- NetBeans 8.0的五个新性能提示
NetBeans 8.0引入了几个新的Java提示 . 尽管有许多与Java Persistence API相关的新提示,但我还是关注Performance类别中的五个新提示. NetBeans 8. ...
- 现代化Java代码的七个NetBeans提示
在" 七个不可或缺的NetBeans Java提示"一文中 ,我谈到了一般使用NetBeans提示的问题,然后重点介绍了七个提示. 接下来列出了该帖子中强调的七个提示: 可疑方法调 ...
- 如何用TestNG满足开发自测?
写在前边 用单元测试Junit完全可以满足日常开发自测,为什么还要学习TestNG,都影响了我的开发进度! 最近技术部老大突然宣布:全体开发人员必须熟练掌握自动化测试框架TestNG,就有了上边同事们 ...
- Seam的好帮手 - Seam Gen 生成工具
Seam Gen是什么 Seam Gen(也叫seam)用来生成seam框剪使用的代码,seam.bat(Windows)和seam(Linux/Unix)使用Ant来生成Seam工程和源代码,使用S ...
- netbeans6.8_NetBeans 8.0的五个新性能提示
netbeans6.8 NetBeans 8.0引入了几个新的Java提示 . 尽管有很多与Java Persistence API相关的新提示,但我还是关注Performance类别中的五个新提示. ...
- java命令行参数工具_Java方法中的参数太多,第8部分:工具
java命令行参数工具 在我的系列文章的前七篇文章中,有关处理Java方法中期望的参数过多的内容集中在减少方法或构造函数期望的参数数量的替代方法上. 在本系列的第八篇文章中,我将介绍一些工具,这些工具 ...
- Java方法中的参数太多,第8部分:工具
在我的系列文章的前七篇文章中,有关处理Java方法中期望的参数过多的内容集中在减少方法或构造函数期望的参数数量的替代方法上. 在本系列的第八篇文章中,我将介绍一些工具,这些工具可帮助您确定可能存在过多 ...
最新文章
- kvm上添加万兆网卡_部署kvm(二)
- js 判断一个元素是否存在
- 配置腾讯云服务器-2021-3-27
- iphone完整版的http上传请求协议
- Ubuntu18.04 给整个目录及子目录赋权限
- vue中this.$router.push()路由传值和获取的两种常见方法
- aop实现原理_SpringAOP原理分析
- 创建python虚拟环境
- 【前端自动化构建】之 自动化部署
- 视频怎么转化成动态图?巧用视频转gif生成器
- MSXML2.DOMDocument
- 期货交易中的重仓操作
- 采用原笔迹电子签名有什么好处
- EasyRecovery15数据恢复软件相关使用教程
- 短信验证码登录,以及第三方登录
- shell那点事儿——运维工程师必会shell知识
- Unity脚本控制更换材质球
- 亲测仿养了个养三消游戏源码+带后台版
- SSL 1580——泽泽在埃及
- 网络乞讨?网络越来越像真实社会了!
热门文章
- java作为kafka生产者实验及Expiring超时问题解决
- SpringBoot整合Shiro权限框架
- 组装一台计算机 java_如何在同一台计算机上安装多个Java版本
- java中延迟_Java中的延迟分配
- hashmap java_Java – HashMap详细说明
- activiti异步执行_对基于消息队列的Activiti异步执行器进行基准测试
- matchers依赖_Hamcrest Matchers的高级创建
- 新版本的Selenium 4 Alpha会有什么期望?
- Java中的LinkedHashMap
- 带Spring Boot的GWT