How to use FeatureSpec with maven-scala-plugin

108 views
Skip to first unread message

Heiko

unread,
Nov 2, 2009, 8:55:31 AM11/2/09
to scalatest-users
Hi,

which is the easiest way to run FeatureSpecs from the Maven test phase
when using the maven-scala-plugin?

Thanks,

Heiko

Jon-Anders Teigen

unread,
Nov 2, 2009, 4:56:39 PM11/2/09
to scalate...@googlegroups.com
Hi Heiko.

There are lots of ways to run scalatest from maven. These are the ones
I know of (some not applicable to FeatureSpecs)

1* JUnit3Suite - turns your tests into (as the name suggests) JUnit 3
tests. Surefire will happily execute these ("Bad thing" is that you
have to follow JUnit3 conventions for your tests)

2* @RunWith(classOf[JUnitRunner]) - turns your tests into JUnit4
tests. Surefire will happily execute these too. Works with all the
cool scalatest stuff (including FeatureSpec)

3* TestNGSuite. Turns your tests into TestNG tests. I havent tried
this one myself, but I guess it works just like the JUnit3Trait.

4* (the secret trick) Run the tests using the pojo-test-support in
surefire. Surefire finds tests by filename and will execute any method
that starts with "test" on properly named non-{junit, testng} classes.
The trick is to have one method starting with "test" in each class
executing scalatest.
E.g

class FooTest extends Spec with ShouldMatchers {
def test_it = execute() // test_it is called by surefire. calling
execute runs your hole scalatest

describe("2 + 2"){
it("should be 4"){
2 + 2 should be (4)
}
}
}

5* maven-scalatest-plugin - There is a maven plugin for scalatest. It
will run all kinds of scalatests. Example pom files can be found in
src/it.

6* maven-antrun-plugin - wire up the scalatest ant task and execute it
in the test phase.

Options 2,4,5 and 6 should work with FeatureSpecs

To really answer your question, the easiest to just get started is
probably number 2 - The @RunWith annotation. In the long run you might
find it a bit tedious having to add that annotation to every single
test, so a more pleasant long term solution is 5 and 6.

/j

Heiko Seeberger

unread,
Nov 3, 2009, 1:31:17 AM11/3/09
to scalate...@googlegroups.com
Hi Jon,

Thank you for your detailed answer!

2009/11/2 Jon-Anders Teigen <jte...@gmail.com>


 1* JUnit3Suite - turns your tests into (as the name suggests) JUnit 3
tests. Surefire will happily execute these ("Bad thing" is that you
have to follow JUnit3 conventions for your tests)

Really too bad.
 
2* @RunWith(classOf[JUnitRunner]) - turns your tests into JUnit4
tests. Surefire will happily execute these too. Works with all the
cool scalatest stuff (including FeatureSpec)

That's fine for me. I have not got it working on my own, but now I tried again and as it still was not working I took a look into the maven-surefire-plugin docs. Well, reading the docs is always a good idea ;-)
=> I have to stick to TestXxx or configure surefire to use my XxxSpec classes.
Cool! It's up and running now.
 
4* (the secret trick) Run the tests using the pojo-test-support in
surefire. Surefire finds tests by filename and will execute any method
that starts with "test" on properly named non-{junit, testng} classes.
The trick is to have one method starting with "test" in each class
executing scalatest.
E.g

class FooTest extends Spec with ShouldMatchers {
 def test_it = execute() // test_it is called by surefire. calling
execute runs your hole scalatest

 describe("2 + 2"){
   it("should be 4"){
      2 + 2 should be (4)
   }
 }
}

Did not work for me:
Tests in error: 
  initializationError(com.lookingglass.authentication.impl.lib.TestAll)
Tests run: 1, Failures: 0, Errors: 1, Skipped: 0

But don't worry, I will go for solution 2.
 
5* maven-scalatest-plugin - There is a maven plugin for scalatest. It
will run all kinds of scalatests. Example pom files can be found in
src/it.

Cool!
Are there any releases?

Cheers,

Heiko

--

My job: weiglewilczek.com
My blog: heikoseeberger.name
Follow me: twitter.com/hseeberger
OSGi on Scala: scalamodules.org
Lift, the simply functional web framework: liftweb.net
Reply all
Reply to author
Forward
0 new messages