Unfortunately, I'm not very familiar with Spring. I looked at this:
It looks like Spring may be assuming JUnit, or at least JUnit and
TestNG. But if Spock works that probably you need a JUnit RunWith
annotation. Did you try putting a RunWith(classOf[JUnitRunner])
annotation on your ScalaTest class, as shown here:
http://www.scalatest.org/scaladoc/1.6.1/#org.scalatest.junit.JUnitRunner
I think you'd need to ask JUnit to run your ScalaTest suites as well
instead of having ScalaTest do it solo. If you have trouble with that
let me know.
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
>
--
Bill Venners
Artima, Inc.
http://www.artima.com
On Fri, Oct 21, 2011 at 6:10 AM, Replicator <weba...@gmail.com> wrote:
> Bill,
>
> Thanks for a quick response.
>
> I have tried @RunWith(classOf[JUnitRunner]) as well as
> @RunWith(classOf[SpringJUnit4ClassRunner]), but it does not seem to do
> it.
>
> When you mention "JUnit to run your ScalaTest suites as well
> instead of having ScalaTest do it solo" => do you mean all my test
> will have to extend "JUnitSuite"? Would that mean I would need to
> change the way the tests are written ( e.g. would not be able to use
> WordSpec, etc.. )?
>
No need to extend JUnitSuite. What I mean is how you run it. There are
lots of ways to run, so I'm not sure how you are running it. But for
example from the command line, you can ask ScalaTest to run something
like this:
scala -cp scalatest-1.5.jar:junit-4.4.jar org.scalatest.tools.Runner
-p . -o -s ExampleSuite
Or JUnit to run it like this:
scala -cp .:scalatest-1.5.jar:junit-4.4.jar org.junit.runner.JUnitCore
ExampleSuite
Probably you're doing the latter somehow through Spring. How are you running?
The other thing, though, is if you use JUnitSuite, that's just a way
to write @Test methods in JUnit, so I would think for sure that should
work with Spring. But if you want to use something more native like
FreeSpec or FlatSpec, then JUnitSuite won't satisfy you.
Bill
If you're using ScalaTestAntTask, then that's ScalaTest running the
tests. What I'd try instead is use the junit ant task to run them. I
don't know if that will fix your problem, because I don't know what
the Spring annotations are doing. But my guess was, that if it works
with Spock, then it should work with a JUnitRunner annotation on a
ScalaTest WordSpec. I may be wrong though, because Spock also has
tests as methods. It may be that Spring needs to see test methods and
test functions won't do. Try running a WordSpec through the JUnit ant
task and let me know if that works. If not, I'll dig deeper into the
Spring stuff.
Bill
On Fri, Oct 21, 2011 at 12:27 PM, Replicator <weba...@gmail.com> wrote:
> Hi Bill,
>
I think you can just make a SpringAkkaLifecycle trait that extends
BeforeAndAfterAll and mix that into your WordSpec subclasses, and/or
you can make a trait that extends WordSpec and BeforeAndAfterAll and
then that becomes your SpringAkkaWordSpec. The tricky part is the
contextReloader. I'm guessing that's a ClassLoader. The first thing
I'd try is simply putting it into SpringAkkaLifecycle. You probably
have to annotate each test class with @Resource, rather than just
annotating the trait. That should work, but if not let me know and I
have another idea. It depends on how Spring works together with vars
brought in from traits.
import org.scalatest.Suite
import org.scalatest.BeforeAndAfterAll
trait SpringAkkaLifecycle extends BeforeAndAfterAll { this: Suite =>
var contextReloader: ClassLoader
override def beforeAll() {
// contextReloader.reinjectDependencies(this)
// ...
}
override def afterAll() {
// Actors.kill()
// ...
}
}
Also, not sure if you can make that var private and Spring can still
access it, but if so I'd make it private. You will need the "this:
Suite =>" self-type to get it to compile. It means this can only be
mixed into a org.scalatest.Suite (which WordSpec extends). Let me know
if you have any trouble getting this to work.