How to run single spec2 test with maven? - scala

I have a scala class with several spec2 tests in it and maven as build tool. I can't find how I can launch one single spec2 test using maven. Is it possible at all?

Related

Run only one package test cases scala

I have the package structure as:
src -> test -> scala -> notification
Inside notification i have two packages unit and integration.
unit package has the unit tests and integration package has integration tests. I want to execute only the unit test cases. Is there i way i can do it by sbt test only?
for one class, i know it can be done like this:
I have tried for the one class but do not know how to do it for a pacakge.
sbt "test:testOnly *LoginServiceSpec"
testOnly allows you to run wildcards using *. So if all your tests are in package namespace x you can call
> testOnly x.*
This wildcard can be put everythere, so if you have a subpackage in x, but all your tests end with e.g. Spec you could run
> testOnly x.*Spec
However if you are using integration test I recommend creating a separate configuration for them so that you would run:
> test
for unit tests and
> it:test
for integration test. Then you would put them in src/it/scala. directory.
Try this
sbt "test:testOnly notification.unit.*"

Cannot "Run as JUnit Plug-in test" on test plugin/package (JUnit5)

I'm trying to add JUnit5 support in my Eclipse RCP application. It almost works, because for now I can:
Use Maven to build whole application and run tests with Tycho
Run single JUnit5 tests (creating run configuration on specific class) in
Eclipse
Run single JUnit5 tests in Run as JUnit Plug-in test mode in Eclipse
Run multiple JUnit5 tests in Run as JUnit test mode in Eclipse
What I'm trying to achieve now is to be able to run whole sets of test classes in plug-in test mode. For JUnit4-based plug-ins I could simply right-click on whole package or even whole plug-in and invoke Run As -> JUnit Plug-in test.
When I do the same operation on JUnit5 tests I get an error: No tests found with test runner 'JUnit 5'.
My current configuration for such plug-ins looks as follows:
According to official instructions in MANIFEST.FM I have Import-Package dependencies:
org.junit.jupiter.api,
org.junit.jupiter.params,
org.junit.jupiter.params.provider
and org.junit as Require-Bundle dependency
In order to run tests in Eclipse IDE I've also added JUnit 5 library to Java Build Path of the plugin. I coudn't add JUnit 5 runner dependencies to MANIFEST.FM instead, because of conflict with Tycho.

How to run all Specs2 tests under IntelliJ IDEA?

In my Scala project, my Specs2 tests are structured as follows:
src/test/scala
-> my.package
---> my.package.sub1
------> SomeTest1
------> SomeTest2
---> my.package.sub2
------> SomeTest3
I'm using SBT to build all of this, and I can use sbt test to run all tests in my package.
I'd like to use IntelliJ IDEA's built-in Specs2 run configuration support. I point it to use all tests in my.package.
Running this yields the error message Error running <run config name>: Not found suite class. It cannot find Specs2 test suites. IDEA runs my tests if I point it to a subpackage.
How do I configure IDEA to look in all packages and run all the test suites it finds?
I've managed to run all my Specs2 tests in IDEA 13.1.4 and the more recent 14.0.1 using All in package for Test kind and In whole project or In single module for Search for tests. I left Test Package field empty.
I had to create this configuration manually.
You may want to use Ctrl+Shift+F10 to create a Specs2 configuration and then modify it accordingly.

How to compile tests with SBT without running them

Is there a way to build tests with SBT without running them?
My own use case is to run static analysis on the test code by using a scalac plugin. Another possible use case is to run some or all of the test code using a separate runner than the one built into SBT.
Ideally there would be a solution to this problem that applies to any SBT project. For example, Maven has a test-compile command that can be used just to compile the tests without running them. It would be great if SBT had the same thing.
Less ideal, but still very helpful, would be solutions that involve modifying the project's build files.
Just use the Test / compile command.
Test/compile works for compiling your unit tests.
To compile integration tests you can use IntegrationTest/compile.
Another hint to continuously compile on every file change: ~Test/compile
We have a build.sbt file that is used for multiple projects. Doing sbt test:compile compiled the tests for every single project and took over 30 minutes.
I found out I can compile only the tests for a specific project named xyz by doing:
sbt xyz/test:compile
Using sbt version 1.5.0 and higher test:compile returns deprecation warning.
Use Test / compile.
(docs)

m2eclipse: Like "mvn test" but with GUI?

We have a multi-module Maven setup with a master pom.xml that includes all the others. So mvn test from the root directory runs all our unit tests, with textual output.
I can do Run / Run As / JUnit Test to run a single test class with a graphical test runner.
Question: How do I combine the two, so that I can run all the tests that mvn test runs but with a graphical runner, like the one from Run / Run As / JUnit Test?
Create an eclipse project with all your modules as Maven Dependecies and then create a JUnit Suite which incorporates all tests. Eclipse's JUnit Runner then will execute all declared Tests if you run this suite.
In Eclipse Juno, assuming your project is a Maven Project, you can just right click the project name in the Project Explorer and select Run As ... jUnit test. Alternatively you can produce the same text output you get from mvn test by selecting Run As ... Maven test