Java Moods

  • Subscribe to our RSS feed.
  • Twitter
  • StumbleUpon
  • Reddit
  • Facebook
  • Digg

Saturday, 28 November 2009

Unit and Integration Testing with Maven, Part 1

Posted on 08:39 by Unknown

Test Types

In my last post, I talked about integration testing with Maven's Cargo plugin and JBoss Application Server. Now let's see how integration testing fits into an overall testing strategy with Maven.

When thinking about tests and testing strategies, there is one important thing to keep in mind: integration tests are not unit tests (even though JUnit may be used to write integration tests). For the sake of completeness, let's pin down the main characteristics of both:

Unit Tests:

  • are testing a small piece of code in isolation
  • are independant from other tests
  • are usually written by software developers
  • have to be very fast because they are run quite often

In contrast, Integration Tests:

  • individual software modules are combined and tested as a group
  • are usually much slower than unit tests because a context has to be established (Spring, database, web server etc.)
  • normally are run after unit testing
  • may be created by QA team using tools, but also by developers using JUnit test cases (which still does not turn them into unit tests)

Testing with Maven

As you know, Maven Build Lifecycle provides phases both for testing and integration testing. Related phases are:

...
generate-test-sources
generate-test-resources
process-test-resources
test-compile
process-test-classes
test
...
pre-integration-test
integration-test
post-integration-test
...

Unfortunately, Maven does not support separate source directories for both test types. This is really complicating things (as we'll see in a minute). There have been some discussions on how to fix that, but I don't think it made it into Maven 3 (not quite sure, though).

Hence, what we need to have is this:

  • Both unit and integration tests have to be compiled by javac.
  • Nevertheless, they should be clearly separated from each other by a path or file name pattern.
  • Unit tests have to be run in test lifecycle phase, and the build should stop if they do not succeed.
  • Integration tests should be run in integration-test phase, and at least the post-integration-test phase has to be run independantly of test result (to be able to shutdown a running container, close database connections etc.).

The next part of this small series will show how these requirements can be met with Maven and what has to be configured, so please stand by...

Email ThisBlogThis!Share to XShare to FacebookShare to Pinterest
Posted in Maven, Testing | No comments
Newer Post Older Post Home

0 comments:

Post a Comment

Subscribe to: Post Comments (Atom)

Popular Posts

  • DocBook with Maven Issue
    We are using DocBook for writing technical documentation for all our projects and in-house frameworks. We are actually quite happy with thi...
  • How big is BigDecimal?
    Lately, there was a debate in our company about rounding of numbers, more specific on how, when and where to do that. One of the questions w...
  • Eclipse: User Operation is Waiting, and Waiting, ...
    I am using Eclipse since quite a long time, sometimes around 2002. That was version 2.0, if I remember correctly. Since then, I have always ...
  • Google and the Crystal Ball
    Google brought us the Web Search. They brought us the Maps. They brought us their Mail, the News, the Images, the Videos... In other words, ...
  • Spring: Use Custom Namespaces!
    Have you ever heard of custom XML namespaces for Spring? I know you love Spring (like I do), so... probably yes. They are available since Sp...
  • Jenkins: Pimp It Up!
    Some days ago, I started to review what plugins are available for Jenkins, my favorite CI server . I haven't done so for a long time, so...
  • Maven vs. Ant: Stop the Battle
    Maven? Ant? Oh boy, how this bothers me. The endless debate and religious battle about which build tool is the better build tool, no, is the...
  • Checkstyle: One and Only Configuration File?
    The Checkstyle Challenge When you are using both Eclipse and Maven, you are probably facing the same challenge like we do: you would like to...
  • The Way From Hudson To Jenkins
    Some time has gone by since the Hudson/Jenkins fork ... and there has been even more talk in the community. However, slowly the dust settles...
  • HDD / SSD Battle
    The Problem You know, the laptop I'm using for my daily work job is not the fastest one. In contrast, it's more than 5 years old and...

Categories

  • BestPractices
  • Cargo
  • Checkstyle
  • Eclipse
  • Google
  • Hudson
  • Java
  • JBoss
  • JEE
  • Jenkins
  • JUnit
  • Maven
  • Nexus
  • oAW
  • Optimization
  • OSGi
  • Performance
  • Profiles
  • QA
  • Size
  • Spring
  • Testing
  • Tools
  • WebApp
  • Windows

Blog Archive

  • ►  2011 (5)
    • ►  May (1)
    • ►  April (1)
    • ►  March (2)
    • ►  February (1)
  • ►  2010 (11)
    • ►  October (2)
    • ►  September (1)
    • ►  April (1)
    • ►  March (1)
    • ►  February (4)
    • ►  January (2)
  • ▼  2009 (30)
    • ►  December (3)
    • ▼  November (4)
      • Unit and Integration Testing with Maven, Part 1
      • Integration test with Maven, Cargo and JBoss
      • JBoss and Maven
      • Spring dm Server Considered Cool?
    • ►  October (2)
    • ►  September (3)
    • ►  June (4)
    • ►  May (5)
    • ►  April (4)
    • ►  March (5)
Powered by Blogger.

About Me

Unknown
View my complete profile