JUnits之间的差异?

时间:2018-03-22 19:43:47

标签: java maven testing intellij-idea junit

我在IntelliJ中创建了一个Java Maven项目(多项式操作),我想创建一个JUnit。我发现有很多类型的JUnits,例如:

  • Arquillan JUnit4
  • Arquillan TestNG
  • Groovy JUnit
  • JUnit3
  • JUnit4
  • JUnit5
  • 斯波克
  • TestNG的

有人可以解释一下他们之间有什么区别和/或哪一个最好用?

谢谢!

2 个答案:

答案 0 :(得分:3)

有关JUnit版本3和4之间的差异列表,请查看this question

有关JUnit 4和5之间的差异,请参阅here。从本质上讲,当涉及到更多功能时,主要存在差异。 JUnit 5有一些更多的断言和重复测试,但不支持低于8的Java版本。

有关TestNG和JUnit的比较,请参阅here。基本上,JUnit和TestNG之间有很多相似之处,注释有点不同,您可以通过TestNG中的xml文件捆绑测试。

答案 1 :(得分:3)

Arquillian JUnit vs JUnit

An Arquillian JUnit test is a JUnit test with some extra features.

  • Your test class should contain @RunWith(Arquillian.class).
  • You can use dependency injection with @Inject.
  • Your tests can run in a container (execution environment) that is configured and managed via Arquillian. (Your test class needs a method with the @Deployment annotation for that.)
  • Thus, integration tests become more real than the simpler solution of mocking container resources. There are Arquillian container adapters for Tomcat, Undertow, Jetty, JBoss, OSGi, etc., and you can create your own adapter.
  • Your project will need a test dependency in your pom/gradle file to org.jboss.arquillian.junit : arquillian-junit-container.

See the documentation for more information.