Running multiple test suites using maven-karma-plugin
The maven-karma-plugin allows running your jasmine tests via karma from maven. For the most part, the documentation given in the readme.md at https://github.com/karma-runner/maven-karma-plugin is sufficient if you just want to run unit tests using karma. However, if you want to use the karma to run your unit tests as well as your e2e tests, you need to specify it in your pom.xml in a slightly different way.
Firstly, the
After looking at the source of the maven-karma-plugin, one can easily understand that the
Firstly, the
<configuration />
goes inside an <execution />
. Then every <execution />
needs to have an <id />
which should be unique.<plugin>
<groupId>com.kelveden</groupId>
<artifactId>maven-karma-plugin</artifactId>
<version>1.1</version>
<executions>
<execution>
<id>unit</id>
<goals>
<goal>start</goal>
</goals>
<configuration>
<browsers>PhantomJS</browsers>
</configuration>
</execution>
<execution>
<id>e2e</id>
<goals>
<goal>start</goal>
</goals>
<configuration>
<browsers>PhantomJS</browsers>
</configuration>
</execution>
</executions>
</plugin>
If you run mvn test
right now, you would see that both the times karma executes, it runs the same tests, which is not really useful. So, the next step is to configure one <execution />
to pick up our configuration file for karma e2e. Now, this is not quite specified in the documentation, all it says is that any elements under <configuration />
are directly passed onto karma as command line arguments like <browsers>PhantomJS</browsers>
translates to --browsers PhantomJS
. That's sufficient if we need to specify a named argument, but the configuration file itself isn't a named argument.After looking at the source of the maven-karma-plugin, one can easily understand that the
<configuration />
can also accept a <configFile />
which is actually passed as the configuration file to karma. Thus, our final configuration should look like this:<plugin>
<groupId>com.kelveden</groupId>
<artifactId>maven-karma-plugin</artifactId>
<version>1.1</version>
<executions>
<execution>
<id>unit</id>
<goals>
<goal>start</goal>
</goals>
<configuration>
<browsers>PhantomJS</browsers>
</configuration>
</execution>
<execution>
<id>e2e</id>
<goals>
<goal>start</goal>
</goals>
<configuration>
<configFile>karma-e2e.config.js</configFile>
<browsers>PhantomJS</browsers>
</configuration>
</execution>
</executions>
</plugin>
Comments
Post a Comment