9

I made a Java Maven project (Operations on Polynomials) in IntelliJ and I want to create a JUnit. I found that there are many types of JUnits, such as:

  • Arquillan JUnit4
  • Arquillan TestNG
  • Groovy JUnit
  • JUnit3
  • JUnit4
  • JUnit5
  • Spock
  • TestNG

Can someone explain me what are the differences between them and/or which one is the best in use?

Thank you!

  • 2
    They are different types of unit (not different types of JUnit) testing frameworks. JUnit is a type of unit testing framework so is TestNG. JUnit is quite popular you can start with it. – isank-a Mar 22 '18 at 19:50
  • You should just pick JUnit 5. To do something similar like operations on polynomials, then you don't need to have the more complex features of the others. And no need to use the older Junit 3 or 4. – Janac Meena Jul 31 '19 at 16:12

2 Answers2

8

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.

Paulo Merson
  • 13,270
  • 8
  • 79
  • 72
6

For a list of differences between JUnit versions 3 and 4 please check out this question.

For differences between JUnit 4 and 5 please refer here. Essentially, there are mostly differences when it comes to more functionality. JUnit 5 has some more assertions and repeated tests, but does not support Java versions lower than 8.

For a comparison of TestNG and JUnit please refer here. Essentially, there are a lot of similarities between JUnit and TestNG, the annotations are a bit different and you can bundle the tests via xml files in TestNG.