Project setup

POM

Maven dependencies

Add JUnit dependency to your POM. Use the version used by Light Air itself.

<dependency>
 <groupId>junit</groupId>
 <artifactId>junit</artifactId>
 <version>4.11</version>
 <scope>test</scope>
</dependency>

Alternatively, you can use TestNG instead of JUnit:

<dependency>
 <groupId>org.testng</groupId>
 <artifactId>testng</artifactId>
 <version>6.8.13</version>
 <scope>test</scope>
</dependency>

Add Light Air dependency to your POM:

<dependency>
 <groupId>net.sf.lightair</groupId>
 <artifactId>light-air</artifactId>
 <version>3.0.1</version>
 <scope>test</scope>
</dependency>

Have an slf4j runtime compatible with slf4j used by Light Air. Logback is recommended.

<dependency>
 <groupId>ch.qos.logback</groupId>
 <artifactId>logback-classic</artifactId>
 <version>1.0.0</version>
 <scope>test</scope>
</dependency>

Test resources

The XML dataset files are expected to be next to the test class, in the same package. This way you are not required to chase them all over the project or switch regularly between the test class directory and test resources directory.

To support this properly in Maven, use the following:

<build>
 <testResources>
  <testResource>
   <directory>src/test/resources</directory>
  </testResource>
  <testResource>
   <directory>src/test/java</directory>
   <includes>
    <include>**</include>
   </includes>
   <excludes>
    <exclude>**/*.java</exclude>
   </excludes>
  </testResource>
 </testResources>
</build>

Integration tests profile

As Light Air tests require the application to be deployed and running on an application server, it is typically not desirable that they be run as unit tests in the Maven test lifecycle phase.

A way to approach this issue is to name the tests with "*IT.java" suffix (as opposed to "*Test.java"). This excludes them from the Maven test lifecycle phase. Next, define a profile to run the Light Air tests:

<profiles>
 <profile>
  <id>it</id>
  <build>
   <plugins>
    <plugin>
     <!-- replace this with your app server maven plugin: -->
     <groupId>my.app.server</groupId>
     <artifactId>my-app-server-maven-plugin</artifactId>
     <executions>
      <execution>
       <id>deploy-pre-integration-test</id>
       <phase>pre-integration-test</phase>
       <goals>
        <goal>my-app-server-deploy-goal</goal>
       </goals>
      </execution>
     </executions>
    </plugin>
    <plugin>
     <groupId>org.apache.maven.plugins</groupId>
     <artifactId>maven-surefire-plugin</artifactId>
     <version>2.19</version>
     <executions>
      <execution>
       <id>integration-test</id>
       <phase>integration-test</phase>
       <goals>
        <goal>test</goal>
       </goals>
       <configuration>
        <includes>
         <include>**/*IT.java</include>
        </includes>
       </configuration>
      </execution>
     </executions>
    </plugin>
   </plugins>
  </build>
 </profile>
</profiles>

The example above also includes a template for the deployment of the packaged application to an application server. You would replace that with a configuration corresponding to your particular application/web server.

Now, you can package your WAR file, deploy it to application server and execute all Light Air integration tests by issuing:

mvn clean install -Pit

where -Pit activates the "integration tests" profile.

After that, you can open any test in your IDE and run it as an ordinary unit test to take advantage of IDE support.

Properties file

Create light-air.properties file in src/test/resources with the following content (example for H2 database):

# Database connection
database.driverClassName=org.h2.Driver
database.connectionUrl=jdbc:h2:~/data/my-project/db;AUTO_SERVER=TRUE;DB_CLOSE_ON_EXIT=FALSE
database.userName=sa
database.password=
database.schema=PUBLIC

# Set the maximum allowable difference of temporal column values in verification
# This value should be greater than the maximum duration of any test case (on any environment)
time.difference.limit.millis=5000

Read more about configuring Light Air.

Be aware, that Light Air tests must connect to the same database instance as the application running within the application server.
Therefore you are looking to access the database in a "server mode", or via "TCP connection", as opposed to "in-memory mode" or "embedded mode".

The same connection URL must be configured for the data source of the application in the application server.

Generate XSD files

Use the LightAir Maven plugin (or call Api.generateXsd) to generate XSD files from the database.

Logback test configuration file

If you use Logback as the slf4j runtime, create a file named logback-test.xml in src/test/resources with content recommended on the Logback site.

This file lets you manage logging in tests, including log output from Light Air.

(Note: When another dependency overrides slf4j API with a conflicting incompatible version you may have to override it explicitly in POM.)

Next: Write a test >>