How to run integration-test with scalatest-maven-plugin?

2,269 views
Skip to first unread message

bewan...@gmail.com

unread,
Mar 10, 2015, 3:05:13 PM3/10/15
to scalate...@googlegroups.com
To my understanding, scalatest write integration tests like unit test. And scalatest-maven-plugin seems to support "mvn test" only.

If I want to run an integration test which need to set up a Cassandra server, how could I start the embedded Cassandra server before all integration tests and shutdown it after all integration tests?

Are there some hooks in scalatest?

Bill Venners

unread,
Mar 10, 2015, 3:13:55 PM3/10/15
to scalate...@googlegroups.com
Hi,

The intended approach is to make a Suites class that mixes in
BeforeAndAfterAll, use beforeAll and afterAll to start and stop
Cassandra, then place all your integration tests in as nested suites.

http://doc.scalatest.org/2.2.4/index.html#org.scalatest.Suites

http://doc.scalatest.org/2.2.4/index.html#org.scalatest.BeforeAndAfterAll

Bill
> --
> You received this message because you are subscribed to the Google
> Groups "scalatest-users" group.
> To post to this group, send email to scalate...@googlegroups.com
> To unsubscribe from this group, send email to
> scalatest-use...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/scalatest-users?hl=en
> ScalaTest itself, and documentation, is available here:
> http://www.artima.com/scalatest
> ---
> You received this message because you are subscribed to the Google Groups
> "scalatest-users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to scalatest-use...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.



--
Bill Venners
Artima, Inc.
http://www.artima.com

bewan...@gmail.com

unread,
Mar 11, 2015, 2:29:50 PM3/11/15
to scalate...@googlegroups.com
Thanks Bill,

Is there a way to generate Suites based on tag or trait? 

For example,

class CassandraSuites extends Suite with BeforeAndAfterAll {

   def nestedSuites = suites discovered using CassandraTest trait or tag
   ...

Bill Venners

unread,
Mar 12, 2015, 3:32:54 AM3/12/15
to scalate...@googlegroups.com
Hi

Unfortunately not as yet. I do want to eventually give ScalaTest's
discovery mechanism an API that you can use similarly to how you've
described, but we have not done that yet. What you'll need to do in
the meantime is just explicitly list the suites.

Bill

Ryan O'Rourke

unread,
Mar 13, 2015, 2:02:54 PM3/13/15
to scalate...@googlegroups.com
Another thing that might come up... do you need your integration tests to run after your application has been fully built and packaged? Perhaps not - Cassandra is a database right? So it's completely external to your project?

But if you do have this requirement, or just want to segregate those tests to run later (perhaps they take a long time to run), you can set up some tests to run in maven's integration-test phase which happens after everything is built. The trick is to have some kind of naming convention on your test suites - we set things up so that tests that end with "IntegrationTest" or "IntegrationSpec" run in this phase, using the following config:

<plugin>
<groupId>org.scalatest</groupId>
<artifactId>scalatest-maven-plugin</artifactId>
<version>1.0-RC1</version>
<configuration>...</configuration>
<executions>
<execution>
<id>test</id>
<goals>
<goal>test</goal>
</goals>
<configuration>
<suffixes>(?&lt;!Integration)(Test|Spec)</suffixes>
</configuration>
</execution>
<execution>
<id>integration-test</id>
<phase>integration-test</phase>
<goals>
<goal>test</goal>
</goals>
<configuration>
<suffixes>(?&lt;=Integration)(Test|Spec)</suffixes>
</configuration>
</execution>
</executions>
</plugin>



On Tuesday, March 10, 2015 at 12:13:55 PM UTC-7, Bill Venners wrote:
Reply all
Reply to author
Forward
0 new messages