Running only unit tests or integration tests. Is it possible with maven/scalatest

868 views
Skip to first unread message

Manish Khettry

unread,
Jul 15, 2013, 4:35:43 PM7/15/13
to scalate...@googlegroups.com
We have a couple of different categories of tests in our projects-- unit or integration tests. This is always done at the level of a class-- i.e. within a wordpsec, all tests are either integration tests or unit tests. We don't tag individual tests.

Is there an easy way, from the command line, to run only unit tests or integration tests. I looked at tags, but they seem to work for individual tests, not an entire spec. We can easily enforce conventions (i.e. all integration tests can be within a package called integration or have the word integration in their name somewhere).

what would be the easiest way to get this going with existing scalatest or the scalatest/maven plugin? 

m

Bill Venners

unread,
Jul 15, 2013, 4:52:46 PM7/15/13
to scalate...@googlegroups.com
Hi Manish,

Can I ask which versions of Scala and ScalaTest are you using?

If you're using a 2.0 milestone or snap release, you can annotate your classes with @UnitTests or @IntegrationTests (if you create those tag annotations). That will then cause the tests inside those classes to be tagged as such, allowing you to include/exclude such tests. But both categories of test class will be discovered and show up in your report, so that's probably not what you want.

Another approach which will also work in 1.8 or later is to use a naming convention for your test classes. Instead of ending your test classes with "Spec", end them with either "UnitSpec" or "IntegSpec". Or USpec and ISpec, etc., if you prefer something more concise. So you might have names like WidgetUSpec and WhatsitISpec, etc.

You can then tell Runner to discard and not inspect any class name that doesn't end in "ISpec" in one target of your build, and in "USpec" in another target. For the details, check out the Suffixes to discover section here:

http://doc.scalatest.org/1.8/index.html#org.scalatest.tools.Runner$@specifyingSuffixesToDiscover

I will have to investigate whether we gave a way to specify this in our maven plugin. I fear we did not, but if so we can add that.

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/groups/opt_out.
 
 



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

Bill Venners

unread,
Jul 15, 2013, 5:17:42 PM7/15/13
to scalate...@googlegroups.com
Hi Manish,

I was in the wrong dir when looking for the maven plugin support for suffixes. It is indeed in there:

<suffixes>comma, delimited, list</suffixes>

Bill



Manish Khettry

unread,
Jul 16, 2013, 8:50:34 PM7/16/13
to scalatest-users
We are using scala 2.10 and scalatest 1.8.

What I was hoping for 

(a) was a way to tag a spec or test suite. 
(b) The maven plugin should be able to run only spec/suite tagged with certain names. 

I know tagging exists but its at a finer granularity so it might need to be called something else. And then ofcourse, other runners will also need to support this. Is this too much to ask?! I'm also happy to look at the code for the plugin and help out if I can.

Manish




On Mon, Jul 15, 2013 at 1:52 PM, Bill Venners <bi...@artima.com> wrote:

Bill Venners

unread,
Jul 16, 2013, 9:30:52 PM7/16/13
to scalate...@googlegroups.com
Hi Manish,

"Tagging" a spec or test suite sounds like an annotation. Would you like to just put some kind of annotation on each one, like:

@Integration
class MySpec extends ...

If so, then perhaps the way to do that is to enhance discovery such that it can be given tags to discover. This sounds familiar, so I believe we've considered this before. We didn't implement it, so perhaps there was a reason why. I'll research further, but it seems a possible feature for Runner and the build tool integrations. This would just be the usual test tags, but you can already tag an entire test class with a test tag. It means that all the tests will be tagged as such, but this discovery feature would just look at classes tagged with the annotation.

Bill

Manish Khettry

unread,
Jul 16, 2013, 9:36:13 PM7/16/13
to scalate...@googlegroups.com
Sure annotation works fine. Then the tools around running tests (runners, plugins) need to change to run tests based on annotation. 

m


Manish Khettry

unread,
Jul 23, 2013, 4:51:12 PM7/23/13
to scalatest-users
On the suffix stuff-- can I specify this through a system property? i.e. it would be really useful to say:

mvn -Dscalatest.suffix=Integration test
mvn -Dscalatest.suffix=Database test

Thanks,
Manish

Reply all
Reply to author
Forward
0 new messages