How to run a single test under FunSuite in Eclipse - eclipse

I'm running unit tests extending org.scalatest.FunSuite using the ScalaJUnit Test (or plain JUnit Test) runner in Eclipse Kepler. When I select a single test to run in the JUnit pane, it runs, but then all the other tests run as well, under a heading designated "Unrooted Tests".
Is there a way to get just the single test I want to run? I hate having to comment-out all the other tests just to simplify the output and save time. Thanks!

It looks like this is possible when using the scalatest plugin for Eclipse (see this page: http://www.scalatest.org/user_guide/using_scalatest_with_eclipse ) and version 2.0 or later of ScalaTest itself. In my case I had already found and installed the plugin, but I needed to upgrade the version of ScalaTest.
I performed the upgrade by changing the scalatest line in build.sbt, then asking SBT to regenerate the Eclipse project. I hope there was a simpler way.

Related

Cucumber and Eclipse IDE; How to make jar for a test case

I'm a Cucumber and Eclipse beginner and have a few questions and hope you can help me to get through this: I created a sample cucumber test scenario, a sample test steps and a cucumber runner. The scenarios runs fine within eclipse IDE (Neon). I used Maven as the dependency manager. I also installed the Maven command line module. The step code is Java.
Here is the (basic) question: How do I create a jar file from my cucumber test scenario so that execute it via command line so that I can bring the test scenario to Jenkins CI? Is there anything I need to do with Maven BEFORE I can build the jar file?
Thanks a lot folks!
If you run Cucumber using the JUnit runner, then all you have to do to run from a command line is to execute Maven and make sure you invoke a life cycle phase that includes running the unit tests. One way would be
mvn test
An example that might get you up and running can be found at
https://github.com/cucumber/cucumber-java-skeleton

How to debug/run a single gatling simulation in IntelliJ IDEA without sbt command?

How could I debug or run the BasicSimulation.scala?
Now I use sbt command to run:
testOnly simulations:BasicSimulation
Is there any other easy way to debug? Thanks.
You can add a simple class and run it by right click->run . Something like here: https://github.com/puppetlabs/gatling-puppet-load-test/blob/master/simulation-runner/src/main/scala/com/puppetlabs/gatling/runner/PuppetGatlingRunner.scala
If you want to run gatling tests inside the intellij, you can go to the edit configurations in the run toolbar on the top left and add a new sbt task.
On the task field enter testOnly simulations:BasicSimulation and that's it.
Normally you should be able to debug it by clicking the debug button, but it doesn't seems to be possible for the gatling tests at least in my configuration.
According to actual documentation this is done like:
gatling:testOnly *BasicSimulation*
Here the Documentation
As with any SBT testing framework, you’ll be able to run Gatling
simulations using SBT standard test, testOnly, testQuick, etc… tasks.
However, since the SBT Plugin introduces many customizations that we
don’t want interfering with unit tests, those commands are integrated
into custom configurations, meaning you’ll need to prefix them with
gatling or gatling-it, eg. gatling:test or gatling-it:test.
(I tested this in sbt console)
Everything is nicely explained in the official documentation page of the gatling project:
http://gatling.io/docs/2.2/extensions/maven_archetype/
Just use their archetype to generate a project in maven and then import in any decent IDE and voilà

How to run tests on every code change in IntelliJ IDEA from Scala sbt project?

I have a new Scala/sbt project set up in IntelliJ IDEA with ScalaTest and jUnit interface successfully installed as dependencies. I have one test that passes when I hit run or debug.
My problem is that it doesn't rerun if I change something. I have to hit run or debug again and then it runs and gives the expected response.
How do I set up IntelliJ IDEA (with or without sbt) to run all tests every time the code changes? Is it possible to run the tests related to the files that were changed only?
As answered in comment by Boris the Spider you can run
> ~test
from sbt shell. Hopefully sbt and IntelliJ can integrate better via sbt server, but I don't think it's currently possible.

Eclipse JUnit runner can't find ScalaTest methods on double click

I'm taking the Martin Odersky Coursera class and the assignments use ScalaTest. It's quite annoying that Eclipse can't locate the test methods on double click or right-click "Go to File" in the JUnit runner.
Upon double click, a "Method 'xxx' not found. Opening the test class." dialog pops up.
Is there a configuration problem or is this a ScalaTest bug/limitation?
Here's a sample ScalaTest from the class:
package recfun
import org.scalatest.FunSuite
import org.junit.runner.RunWith
import org.scalatest.junit.JUnitRunner
#RunWith(classOf[JUnitRunner])
class CountChangeSuite extends FunSuite {
import Main.countChange
test("manual") {
assert(countChange(4,List(1,2)) === 3)
}
}
You can use the ScalaTest Eclipse plugin with ScalaTest 1.8. But when you run your tests it will pop up a GUI. Useful, but not as nice as the ScalaTest 2.0 integration. I think with the Coursera course you are using 1.8.
The actual problem you're having with JUnit is one that we have tried to solve in ScalaTest. JUnit is not only a test framework, it is also a testing platform that you can run other frameworks through via its #RunWith annotation. In this case you're running ScalaTest through JUnit. But you don't get full IDE support with a #RunWith annotation, you just get the ability to run. This is indeed a limitation of JUnit. What you would like is to get IDE support too for that test framework you're running through JUnit (in this case ScalaTest). The only way to do that with JUnit is to write IDE plugins for your test framework, which is a lot of work.
We have been working on that as part of the ScalaTest project, making plugins or helping make plugins that give ScalaTest users full IDE support. But as part of that effort we also came up with the concept of a "Finder" that can be used to give other test frameworks full IDE support when they are run through ScalaTest. (I.e., just as you can run other test frameworks through JUnit, you can also run other test frameworks through ScalaTest.) You can see some examples of Finders giving IDE support at the end of this video (about 10 minutes into the video):
http://skillsmatter.com/podcast/scala/scalatest-scalamock-subcut
Yes, it's a known bug in the JUnit plugin for Eclipse. It's also very hard to solve (for the jun it plugin).
Basically, The Eclipse junit plugin expects there to be a method, which there will be for all java JUnit tests, but this isn't necessarily the case for ScalaTest tests, especially Suites & Specs.
However, you can try out the Scalatest plugin for Eclipse, which should work.
This works for me:
1- Open a console in your folder project and execute "sbt".
2- (without get out from"sbt") execute "eclipse" command.

Using JUnit #Rule in Eclipse's JUnit runner

Eclipse 3.7.2
I just implemented an #Rule in some JUnit 4 tests, but when I run them in Eclipse the MethodRule methods are not being called. It's like the Eclipse test runner doesn't recognize the #Rule implementations and doesn't do anything special with fields that are annotated with #Rule.
I even tried using a "Standard" MethodRule like org.junit.rules.TestName but it doesn't work properly (the test's names are not populated into the instance). Even the example test in the JavaDoc of TestName fails when run in Eclipse.
Is there some trick? Does Eclipse simply not support JUnit Rules?
It turns out that somebody had included a seemingly "required" JAR on the runtime classpath of the project in question. That JAR embeds, among other things it should not, the JUnit packages! So there is this JAR, named something innocuous like our_runtime_library.jar that has some app-specific code along with some unknown (but old) versions of JUnit, Spring, and who knows what else. When running the project as a Unit Test, Eclipse was picking up the JUnit in that JAR instead of its own version (as it should, project-specific libraries always take precedence), the (Eclipse) version that the project is built against.
What a mess; now off to figure out who deserves 50 lashings for this one.
It should work, at least in my Eclipse(in embeded JUnit 4.8).
So you could show your code.
Additional, JavaDoc says: Note that MethodRule is now deprecated, you should be using TestRule instead.