Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Differences between the JUnits?

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!

like image 573
Cherry Danielle Avatar asked Mar 22 '18 19:03

Cherry Danielle


2 Answers

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.

like image 57
Paulo Merson Avatar answered Oct 23 '22 09:10

Paulo Merson


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.

like image 34
Georg Muehlenberg Avatar answered Oct 23 '22 09:10

Georg Muehlenberg