JUnit与TestNG [英] JUnit vs TestNG

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

问题描述

在工作中,我们目前仍在使用JUnit 3来运行我们的测试。我们一直在考虑切换到JUnit 4进行测试,但我现在已经关注TestNG了一段时间。您对JUnit 4或TestNG有什么经验,对于大量的测试似乎更好?编写测试的灵活性对我们来说也很重要,因为我们的功能测试涵盖了广泛的方面,需要以各种方式编写以获得结果。

At work we are currently still using JUnit 3 to run our tests. We have been considering switching over to JUnit 4 for new tests being written but I have been keeping an eye on TestNG for a while now. What experiences have you all had with either JUnit 4 or TestNG, and which seems to work better for very large numbers of tests? Having flexibility in writing tests is also important to us since our functional tests cover a wide aspect and need to be written in a variety of ways to get results.

旧测试将不要重写,因为他们做得很好。我希望在新测试中看到的是测试编写方式的灵活性,自然断言,分组和易于分布的测试执行。

Old tests will not be re-written as they do their job just fine. What I would like to see in new tests though is flexibility in the way the test can be written, natural assertions, grouping, and easily distributed test executions.

推荐答案

我已经使用过两者,但我必须同意Justin Standard,你不应该考虑将现有的测试重写为任何新的格式。无论做出何种决定,两者兼顾都是微不足道的。 TestNG比JUnit更容易配置,但最终它们同样运行良好。

I've used both, but I have to agree with Justin Standard that you shouldn't really consider rewriting your existing tests to any new format. Regardless of the decision, it is pretty trivial to run both. TestNG strives to be much more configurable than JUnit, but in the end they both work equally well.

TestNG有一个简洁的功能,你可以将测试标记为特定的组,然后轻松运行特定组的所有测试,或排除特定组的测试。因此,您可以标记在慢组中运行缓慢的测试,然后在需要快速结果时忽略它们。他们的文档中的一个建议是将某些子集标记为checkin测试,每当您检查新文件时都应该运行。我从未在JUnit中看到过这样的功能,但是如果你没有,那么你就不会真的很想念它。

TestNG has a neat feature where you can mark tests as a particular group, and then easily run all tests of a specific group, or exclude tests of a particular group. Thus you can mark tests that run slowly as in the "slow" group and then ignore them when you want quick results. A suggestion from their documentation is to mark some subset as "checkin" tests which should be run whenever you check new files in. I never saw such a feature in JUnit, but then again, if you don't have it, you don't REALLY miss it.

对于高配置的所有声明,几周前我确实碰到了一个角落的情况,我不能做我想做的事情做...我希望我能记住它是什么,但我想提起它,所以你知道它并不完美。

For all its claims of high configuration, I did run into a corner case the a couple weeks ago where I couldn't do what I wanted to do... I wish I could remember what it is, but I wanted to bring it up so you know that it's not perfect.

TestNG的最大优势是注释...无论如何,JUnit在版本4中添加了。

The biggest advantage TestNG has is annotations... which JUnit added in version 4 anyways.

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

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