JUnit 4 vs TestNG-更新2013-2014 [英] JUnit 4 vs TestNG - Update 2013 - 2014

查看:57
本文介绍了JUnit 4 vs TestNG-更新2013-2014的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

JUnit 4和TestNG曾经具有可比性.这两个测试框架的优缺点是什么?

JUnit 4 and TestNG used to be comparable. What are the pros and cons of the two testing frameworks?

推荐答案

我今天比较了TestNG和JUnit4,根据我在测试框架方面的有限经验,我可以指出的主要优点是TestNG具有更优雅的方式数据提供者概念处理参数化测试的方法.

I was comparing TestNG and JUnit4 today, and the main advantage that I can point out with my limited experience in testing-frameworks is that TestNG has a more elegant way of handling parametrized tests with the data-provider concept.

据我所知,使用JUnit4必须为要使用的每组参数创建一个单独的测试类(使用@RunWith(Parameterized.class)运行).借助TestNG,您可以在一个测试类中拥有多个数据提供者,因此您也可以将单个类的所有测试都保留在一个测试类中.

As far as I can tell with JUnit4 you have to create a separate test class for each set of parameters you want to test with (ran with @RunWith(Parameterized.class)). With TestNG you can have multiple data-providers in a single test class, so you can keep all your tests for a single class in a single test-class as well.

到目前为止,我唯一可以指出的是TestNG相对于JUnit4的好处.

So far that is the only thing that I can point out as a benefit of TestNG over JUnit4.

Intellij IDEA开箱即用地支持TestNG和JUnit.但是,Eclipse仅支持开箱即用的JUnit,并且需要安装TestNG插件才能使其正常工作.

Intellij IDEA includes support for TestNG and JUnit out of the box. However, Eclipse only supports JUnit out of the box and needs a TestNG plugin installed to make it work.

但是,我在使用TestNG时遇到的一个更烦人的问题是,如果您使用PowerMock模拟测试中的依赖项,则您的测试类需要扩展PowerMockTestCase.显然,有一些方法可以配置测试框架需要通过特殊方法或testng.xml套件定义来了解何时使用PowerMock的对象工厂,但是这些方法目前似乎已失效.我不喜欢让测试类扩展测试框架类,这似乎有些骇人听闻.

However, a more annoying problem I ran into with TestNG is that your test classes need to extend PowerMockTestCase if you are using PowerMock to mock dependencies in your tests. Apparently there are ways to configure the object-factory your test framework needs to know about when using PowerMock via a special method, or via the testng.xml suite definition, but those seem to be broken at the moment. I dislike having test-classes extend test-framework classes, it seems hackish.

如果您不使用PowerMock,这当然不是问题,但是总的来说,我会得到更好地支持JUnit4的印象.

If you don't use PowerMock this is not an issue of course, but all in all I get the impression that JUnit4 is better supported.

这篇关于JUnit 4 vs TestNG-更新2013-2014的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆