mandag 1. mars 2010

Maven and Scalatest

I started experimenting with ScalaTest some days ago tempted by the nice looking Feature Specs over here.

mvn scala:cc is continuously compiling my scala code - I wanted to be able to call something like mvn test -Dtest=MyTest from command line as well as for maven to run all my test suites when building.

This is how:

Install the maven-scalatest-plugin:

git clone git://github.com/teigen/maven-scalatest-plugin.git

cd maven-scalatest-plugin && mvn clean install

Update the pom.xml

<!-- disable surefire -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<skipTests>true</skipTests>
</configuration>
</plugin>
<!-- enable scalatest -->
<plugin>
<groupId>com.jteigen</groupId>
<artifactId>maven-scalatest-plugin</artifactId>
<version>1.0-SNAPSHOT</version>
<executions>
<execution>
<goals>
<goal>test</goal>
</goals>
</execution>
</executions>
<configuration>
<testFailureIgnore>true</testFailureIgnore>
<filereports>NCXEHLOWFD file/constrained.txt,file/full.txt</filereports>
<xmlreports>xml</xmlreports>
<htmlreports>html/report.html</htmlreports>
</configuration>
</plugin>

Run tests:

mvn test will now exectue all the scala test suites found after building the project.

However the build is not really necessary when mvn scala:cc is running at the same time.

mvn com.jteigen:maven-scalatest-plugin:1.0-SNAPSHOT:test will only execute the tests.

What if you don't want to run all the suites? 

mvn com.jteigen:maven-scalatest-plugin:1.0-SNAPSHOT:test -Dsuite=mypack.MySuite

Ingen kommentarer:

Legg inn en kommentar