简体   繁体   中英

ScalaTest and Maven: getting started

I have a Maven/Java project I've been working on for years, and I wanted to take JavaPosse 's advice and start writing my tests in Scala. I've written a few tests following ScalaTest's JUnit4 quick start , and now I want these tests to be executed while running "mvn test". How should I do this? What should I put into my pom.xml to allow the tests in src/test/scala to be run side-by-side my old JUnit4 tests?

Cheers

Nik

PS, yes, I've been Googling, but all I could find on the topic were some pre-v1.0 suggestions that I didn't get working

PPS, bonus question: how can I run these tests one-at-a-time by rightclicking them in Eclipse/STS and say "Debug As... ScalaTest" or something similar where I've so far said "Debug As... JUnit Test"?

PPPS, I expect the answer has changed since July '09 ?

The second answer in one of the questions you linked to SHOULD work: Is there a Scala unit test tool that integrates well with Maven?

You annotate your tests with a junit @RunWith annotation and give it the scalatest http://www.artima.com/docs-scalatest-2.0.RC3/#org.scalatest.junit.JUnitRunner

If your Tests also adhere to any naming conventions possibly enforced by Maven, this should work fine.

Note: It doesn't matter what kind of scalatest trait you use. All of them should work. If they don't and Bill Venners doesn't answer to this question, contact him on the ScalaTest mailing list.

Other Note: you can run such test suites in Eclipse using the normal JUnit plugin. But you can't run single tests, since the plugin expects to deduct a method name from the test name, which doesn't work with all types of scalatest tests.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM