Friday
Oct182013

Conditionally Run JUnit Integration Tests with Spring

Ideally, your unit test suites require no external dependencies - those should be mocked out. However, sometimes you want extra assurance that your code works with live endpoints via integration tests.

For example, you might want to make sure that your code can successfully navigate your corporate proxy and firewall to make external web requests. For this, we’ll write tests that only run when a command line parameter is defined.

This demonstration assumes that you’re using Spring’s JUnit Runner and Maven for running your tests. The @IfProfileValue annotation will tell the test runner to only include this test suite if our configured ProfileValueSource returns a “true” for “live-external-tests-enabled”.

Let’s verify that this test suite is ignored by default with the maven command:

You’ll see that you now have a skipped test:

Now, try it again, but this time with our test included:

You’ll now see that the test was run:

The @IfProfileValue annotation can also be used above an individual test.

PrintView Printer Friendly Version

EmailEmail Article to Friend

References (26)

References allow you to track sources for this article, as well as articles that were written in response to this article.
  • Response
    Blake Caldwell - /dev/blake/blog - Conditionally Run JUnit Integration Tests with Spring
  • Response
    Blake Caldwell - /dev/blake/blog - Conditionally Run JUnit Integration Tests with Spring
  • Response
    Response: rocket french url
    Blake Caldwell - /dev/blake/blog - Conditionally Run JUnit Integration Tests with Spring
  • Response
    Blake Caldwell - /dev/blake/blog - Conditionally Run JUnit Integration Tests with Spring
  • Response
    Response: Phil St Ores
    Blake Caldwell - /dev/blake/blog - Conditionally Run JUnit Integration Tests with Spring
  • Response
    Response: Phil St Ores
    Blake Caldwell - /dev/blake/blog - Conditionally Run JUnit Integration Tests with Spring
  • Response
    Blake Caldwell - /dev/blake/blog - Conditionally Run JUnit Integration Tests with Spring
  • Response
    Response: testez moi
    Blake Caldwell - /dev/blake/blog - Conditionally Run JUnit Integration Tests with Spring
  • Response
    Response: testez moi
    Blake Caldwell - /dev/blake/blog - Conditionally Run JUnit Integration Tests with Spring
  • Response
    Response: Phil St Ores
    Blake Caldwell - /dev/blake/blog - Conditionally Run JUnit Integration Tests with Spring
  • Response
    Response: GTA 5 Rank Up Hack
    Blake Caldwell - /dev/blake/blog - Conditionally Run JUnit Integration Tests with Spring
  • Response
    Blake Caldwell - /dev/blake/blog - Conditionally Run JUnit Integration Tests with Spring
  • Response
    Blake Caldwell - /dev/blake/blog - Conditionally Run JUnit Integration Tests with Spring
  • Response
    Pelatihan SDM is a network marketing and training information or training an employee who has worked with many consulting firms and training institutions.
  • Response
    Response: GoPro Stick
    Blake Caldwell - /dev/blake/blog - Conditionally Run JUnit Integration Tests with Spring
  • Response
    Response: GoPro Car Mount
    Blake Caldwell - /dev/blake/blog - Conditionally Run JUnit Integration Tests with Spring
  • Response
    Blake Caldwell - /dev/blake/blog - Conditionally Run JUnit Integration Tests with Spring
  • Response
    I enjoy you because of all of your labor on this blog. My niece loves going through investigations and it is easy to understand why. We know all relating to the dynamic form you offer sensible things through the blog and in addition inspire participation from others on this concept plus ...
  • Response
    Blake Caldwell - /dev/blake/blog - Conditionally Run JUnit Integration Tests with Spring
  • Response
    This is really helpful for java juniors
  • Response
    Response: bola online
    Blake Caldwell - /dev/blake/blog - Conditionally Run JUnit Integration Tests with Spring
  • Response
    Response: GoPro carrying bag
    Blake Caldwell - /dev/blake/blog - Conditionally Run JUnit Integration Tests with Spring
  • Response
    Response: GoPro Suction Cup
    Blake Caldwell - /dev/blake/blog - Conditionally Run JUnit Integration Tests with Spring
  • Response
    Blake Caldwell - /dev/blake/blog - Conditionally Run JUnit Integration Tests with Spring
  • Response
    Response: Copy Writing
    Blake Caldwell - /dev/blake/blog - Conditionally Run JUnit Integration Tests with
  • Response
    Response: togel Online
    Blake Caldwell - /dev/blake/blog - Conditionally Run JUnit Integration Tests with

Reader Comments

There are no comments for this journal entry. To create a new comment, use the form below.

PostPost a New Comment

Enter your information below to add a new comment.

My response is on my own website »
Author Email (optional):
Author URL (optional):
Post:
 
Some HTML allowed: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <code> <em> <i> <strike> <strong>
« Developing Software In a Changing Industry | Main | Don't Rely on EntityManager.persist() for Immediate Insert »