Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Unit Testing

Java-based components in SCA Fabric3 are in most cases simple POJOs with optional annotations. This means that this guide has little to add to the already well-covered topics of test-driven development and unit testing. It is important to note, however, that even with Fabric3's strong support for integration testing (examined below), it remains easier to find and fix a whole class of bugs by running lightweight tests as opposed to a (slower) test-harness.

Integration Testing

Fabric 3 Fabric3 integration tests ensure that component implementations and composites provide the expected functionality and interact with other services and runtime resources in the expected way. They are referred to as 'itests'.

While Fabric 3 Fabric3 does provide a lightweight standalone runtime environment, the recommended way to drive automated integration tests is through the specialized Maven plug-in or Ant TaskGradle or Maven plugin. These handle the creation of an embedded Fabric3 runtime, deployment, and test execution. Fast runtime bootstrap and test execution makes iterative development easier. Since the Maven plug-in and Ant Task Gradle and Maven plugins provide the same execution environment as the standalone server, component behavior verification can be done with little overhead. Use of the Maven plug-in and Ant Task Gradle and Maven plugins also allows integration tests to be initiated in exactly the same way on development machines and the build server.

JUnit Tests

As detailed in the following sections, Fabric3 makes use of JUnit for writing in-container integration tests. Fabric3 provides a test runner that allows JUnit tests to act as components that can be injected with services to be test. When the build is run, the JUnit tests will be executed in a Fabric3 embedded container and their results reported as part of the test phase of the Maven or Gradle build.  Writing a test component is simple - below is an example of how this is done:

Code Block
languagejava
@RunWith(Fabric3Runner.class)
public class HelloWorldTest extends TestCase {
 
    @Reference
    protected HelloWorld helloWorld;
 
    public void testSayHello() {
        assertEquals("Hello, Foo", helloWorld.sayHello("Foo"));
    }
}

 

Page Tree
root@self