Integration Tests with heavy application in JUnit

 

geralt / Pixabay

One of backend’s have very expensive Integration Tests. Complete suite takes about 40 minutes. Many of tests were written in a one big class, just to assure that start and close of backend will take place only one time. Moreover, there is used JUnit Nested Runner from NitorCreations. After backend development finished, there were many bugs repaired in maintenance stage and many features added in small change requests. Adding changes always makes some tests to be added. There was never a good time (and budget) to improve tests. In conclusion: now exists one big class with many subclasses and hundreds of scenarios inside.

 

With help come up JUnit 4.9.

Need to run Java based Integration Tests in a way that Application starts at the beginning and close and the end of the Suite. On of possible solutions is to use org.junit.rules.ExternalResource toghether with @ClassRule from JUnit in version 4.9 or up.

 

public class SomeTest {
    @ClassRule
    public static final ApplicationResources res = new ApplicationResources();
    @Test
    public void testSomething() {
        // Test is in here
    }
}

public class ApplicationResources extends ExternalResource {
    protected void before() {
        // Logic used in @BeforeClass
    }
    protected void after() {
        // Logic used in @AfterClass
    }
}

 

Full solution can be found at: Stack Overflow


 

After just few short hours of development, there are covered most valuable goals:

  • Tests exists in separate classes (per feature)
  • There are Scenarios connected to group of Features and Suites
  • One big Suite run tests by starting backend at the beginning and closing at the end
  • Can run one class separately
  • Can run complete Suite by one click
  • Can run using gradle in CI environment

 

Posted in: Sortware

Tagged as: ,

Advertisements

1
Leave a Reply

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

  Subscribe  
newest oldest most voted
Notify of
trackback

[…] different solution like Integration Tests with heavy application in JUnit or Nested Tests in JUnit probably you would start your application in the code and close it at […]