Difference between Spring TestContext Framework and Jboss Arquillian

My company has developed a medium / large web application over the past 7 years. The application uses Spring Framework (3.0), Hibernate (3.x) and Struts (1.x) among others. Unfortunately, we did not use any automated tests. Now we need to add them to avoid regression errors and start a better development life cycle. Following the best practices for this hard work, I read that we can start with the gui smoke test, followed by integration testing before adding the unit test. So my question is: about the integration test (in the container), which is the difference between Spring TestContextFramework and JBoss Arquillian? I read that Arkillian will support Spring in it final release (http://community.jboss.org/message/563768). Will I have any benefit from its use after stabilization?

Thanks Stefano.

+4
source share
3 answers

I have never used Arquillian, but it seems to have focused on testing EJBs with a focus on deploying in a real container. If your application is based on Spring (+ Hibernate), Spring Testing Support is probably the best choice.

As part of a test case, you can start part of the context of your application (only a small part or almost the whole application) with bullying in the database. You don't need a running container, since Spring is basically standalone. Testing Struts 1.x actions is harder, but I think Arkillian won't help you either.

Also, if your stability in software is your problem, Arkiljan seems to be in the Alpha version right now. But I would definitely give him a chance that I would have to test an EJB-based application. For a Spring application with context caching, transaction demarcation in tests, etc. TestContext Framework is the best choice.

Side note: Consider using TestNG instead of JUnit, since it works much better with TestContext, for example. you have access to Spring beans in setup / stall methods (static in JUnit).

+1
source

I myself am an Arquillian user, but I recommend you stick with Spring's solution. Although it will ultimately be incompatible with the container, efforts are currently focused on Java EE. Your work seems rather complicated, and I would not recommend Aquillian right now.

However, to eliminate some confusion, you can run the built-in tests on Arquillian. It can load the built-in Glassfish or JBoss AS servers and run the test using the "real thing" instead of layouts or alternative implementations. JPA, Interceptors, JTA, XA Datasources, JMS, JSF, Servlet. All available - batteries included;)

Alternatively, you can run a JBoss instance in the background and run the test remotely. Arkillian takes care of the unfolding / testing / unfolding of the cycle - and he quickly flashes!

+1
source

I have never used any of them, but here is my final documentation:

## Spring Integration Tests ##

Spring allows you to run some integration tests without having to deploy to the application server .

Spring testing support unit <testing> and is provided by the Spring TestContext Framework, which is an agnostic of the testing environment used (JUnit, TestNG, etc.).

TestContext Framework provides:

  • WebApplicationContext loading of Spring ApplicationContext and WebApplicationContext , as well as caching of these contexts. [1]

  • Optionally configure instances of your test classes through Dependency Injection. [2]

  • provides transaction management for transaction tests: the structure will create and roll back a transaction for each test.

  • provides abstract classes that can be extended by developers to easily encode JUnit or TestNG test classes.

## Arquillian ##

Arkillian runs integration tests inside a real runtime whose life cycle is managed by Arkillian. Indeed, with Arquillian, your integration tests are either performed inside the container , or interact with the container as a client.

The container may be:

  • built-in or remote Servlet container (e.g. Tomcat, Jetty),
  • Java EE application server (e.g. GlassFish, JBoss AS, Embedded GlassFish),
  • Java SE CDI Environment
  • or any other container implementation

Arquillan:

  • controls the container life cycle (start / stop),

  • Associates a test class with dependent classes and resources in a deployable archive.

  • enhances the testing class (e.g. allowing @Inject, @EJB and @Resource injections),

  • Deploys the archive for testing (expand / expand),

  • captures results and errors.

# How does it work #

Arquillian provides a custom test runner for JUnit and TestNG.

  • When you run your tests, this custom test runner will detect the @RunWith Arquillian .
  • The custom test runner will thus switch the life cycle management of the test from the unit testing system (JUnit or TestNG) to Arquillian.

  • For each test case:

    • Arkillian will use ShrinkWrap to create micro archives. The SharpWrap-enabled classpath control allows Arquillian to declaratively define its own Java EE archive that encapsulates the test class and its dependent resources, but nothing more! This gives you finer control over what you are testing and what resources are available during the test.
    • Arquillian deploys each โ€œmicroarchiveโ€ in the target container (which is configured in the maven profile), I guess one by one.
    • He then coordinates the execution of the test methods and captures the test results using remote communication with the server.
    • Finally, Arquillian unpacks the test archive.
+1
source

Source: https://habr.com/ru/post/1338730/


All Articles