How to run all Specs2 tests under IntelliJ IDEA? - scala

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.

Related

SBT - why sbt giving compilation errors while running?

I am trying to merge two modules into single module. Both are successfully running modules. I merge two modules. And trying to run the test cases.
i am compiling source and testcases by using sbt commands:
sbt
clean
compile
project module-read
test:compile
it:test
Till test:compile everything working fine but after it:test, it showing lot of compilation issues.
Could I know best way of compiling?
The test:compile task will only compile tests within the src/test/scala folder as per the default sbt test configuration.
In order to compile your integration tests (in src/it/scala) you will have to run it:compile .
See http://www.scala-sbt.org/0.13.5/docs/Detailed-Topics/Testing.html#integration-tests for more info.

how to use JUNIT using makefile?

I am very new to JUNIT. I have Makefile to compile my code and which will generate a jar file and now I want to run my JUNIT test case for that.
I not sure how to find out .class file using JAR. I am using LINUX as I know I need a .class file to execute a JUNIT case.
can some one help me?
from http://c2.com/cgi/wiki?UnitTestCookbooks:
I use JavaUnit for my unit tests. For a class Foo, its source is in
Foo.java. Its unit test lives in a separate class, with the source in
TestFoo.java. A command line invokes the unit test, in either console
mode or with a GUI. I use the console mode tester:
java junit.textui.TestRunner TestFoo
I build an "all-in-one" test suite for a package, which runs all of
the unit tests in the package. It's called TestAll. This is usually
the test I run when working on the package.
I add a rule like this to my makefile:
test: TestAll.class
java junit.textui.TestRunner TestAll
when I run "make test", Test'All.class gets built (through another
rule) and then junit is run with the standard command-line.

How to run a single test in scalatest from maven

I have not found any documentation on how to do this. For JUnit the equivalent would be:
mvn -Dtest=org.apache.spark.streaming.InputStreamSuite test
tl;dr mvn test -Dsuites="some.package.SpecsClass"
I found an answer from here and it works:(https://groups.google.com/forum/#!topic/scalatest-users/Rr0gy61dg-0)
run test 'a pending test' in HelloSuite, and all tests in HelloWordSpec:
mvn test -Dsuites='org.example.
HelloSuite #a pending test, org.example.HelloWordSpec'
run all tests in HelloSuite containing 'hello':
mvn test -Dsuites='org.example.HelloSuite hello'
for more details: http://scalatest.org/user_guide/using_the_scalatest_maven_plugin
Found the answer: it is
-DwildcardSuites
So here is the example command line:
mvn -pl streaming -DwildcardSuites=org.apache.spark.streaming.InputStreamSuite test
Update Newer versions of scalatest use
-Dsuites
So the syntax would be:
mvn -pl streaming -Dsuites=org.apache.spark.streaming.InputStreamSuite test
Note that if you have some Java tests in the same module, as much of spark does, you need to turn them off -which you can do by telling surefire to run a test that isn't there
Here is the test that I've just been running
mvn test -Dtest=moo -DwildcardSuites=org.apache.spark.deploy.yarn.ClientSuite
That skips the java test and only runs the scala one.
One thing which scalatest doesn't seem to do is let you run a single test within a suite, the way maven surefire does. That's not ideal if you have one failing test in a big suite.
[Correction 2016-08-22: looks like you can ask for a specific suite by name; look at the other answers below. Happy to be wrong].

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)

How can I skip tests in an SBT build?

I have an SBT 0.7.5 project and its some test cases fail. Until all test cases are fixed, I want to skip tests to generate a JAR. Is there any command line argument that tells SBT to skip all tests, like Maven's -Dmaven.test.skip=true flag?
I had the same problem, I'm using the assembly plugin. In this case, the solution was to modify the build file and add
test in assembly := {}
Instead of using compile, you could use package. The compile tasks also runs the tests, package doesn't.