Running scala tests in IntelliJ - scala

I want to debug a variable in scala metadata.sparkVersion in KMeans.scala using scala test suits in spark KMeansSuite.scala.
I have set my break point. However when I try to run (Or right click) it, I dont see a Run option. How do I fix this?. How should I go about debugging the code.

Please follow the tutorial. You need Scala plugin if you want Idea to undestand ScalaTest. If it is already done:
Right click on test folder and "Mark directory as"-> "Test Sources Root".
Alternative is to annotate the test with
#RunWith(classOf[JUnitRunner]) see here
Then the tests will be executed with JUnit
Or you can have JUnit tests

Related

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.

How to run a ScalaTest form a different project in Eclipse?

I have two Scala projects open in Eclipse (the Scala IDE, more precisely). One project is the main project and the other is where I want to place my tests.
If I place a test file (i.e. a class Test1 extends FlatSpec) in my main project, I can right click on the file and choose "Run Configurations", and it offers me to "Run as ScalaTest - File". However, if I copy that same test file to the second project, right clicking doesn't offer that option. Why is that?
If I am not explaining the situation with enough detail, I'll be glad to add more information.
From ScalaTest guide:
Using ScalaTest in a Scala project
To use ScalaTest in your Scala
project, you must download ScalaTest and include it in build path of
your project.
If it is in your build path, you could just create run-configurations for that particular class.
I've had problems in the past with eclipse and not seeing run java application. I just created the run configurations myself.

How to run a single test under FunSuite in 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.

ScalaTest Run Configuration in Eclipse: cannot find Suite Class

Problem: I cannot setup Run Configurations to run scalatest for the Scalatests in my project.
Steps to reproduce:
Right click on Scala Suite and click on Run as -> Run configurations..
On the left, I see a configuration template for ScalaTest. I click on New and fill the Name but it cannot find the suite-class.
Note: It is mentioned here that I should see Run as -> ScalaTest - Suite but I do not see that option. I tried using context menu in the editor, and in the package explorer
Steps taken:
Using: Scala IDE for Eclipse version: 2.1.0.m3-2_09
Using SBT, assemble project, run eclipse command and then import project and dependencies into Eclipse
Project compiles. ScalaTest code compiles(scalatest_2.9.2-1.8.jar is in the 'Referenced Libraries' configuration)
I've been fighting a similar problem for the past few days; Lily / Jimbo's answer didn't quite match my situation, but helped me find the right direction.
In my case, I was using a third-party library that I'd copied in. The package names of the classes and tests matched, but the folder structure did not -- all of my tests were directly in Play's "/test" folder, rather than in folders that matched the package names. This didn't show any errors, but was broken: packages ought to match folders. When I built the right folder structure underneath test, and recompiled, the expected "Run As -> ScalaTest - Suite" options showed up.
Don't know if your problem is the same, but you might check this if you haven't already found the issue...
This could be caused by a misalignment between the scalatest and the scala eclipse IDE version. Try scalatest_2.9.0-2.0.M5b.jar or scalatest_2.10-2.0.M5b.jar. The former jar definitely works with ide 2.0.9.x so maybe the new version needs the 2.10 jar. Pick your version carefully from here
Willem's answer is what worked for me. Getting both plugins from the same update site (from the list on Scalatest's github site), seemed to work for me using Kepler.
for my case, one click on 'Reimport All Maven Projects' icon, like 'Refresh' icon, solved the problem.
Not sure if you fixed the error, but I had similar a error yesterday and was pulling my hair trying to fix it (none of the suggestions I found by googling seemed to help me). So for me, it turns out that it's as easy as package hierarchy in my test suite.
I am using the play framework, so naturally my folders look like this controllers.package1.package2.... and this applies to my test folders also.
Now my test classes however, have the package definition package1.package2..... (no "controllers" as prefix).
If I run the tests on sbt/play command prompt, it's not a problem. But running them through Eclipse would give me the problem you described.
So anyways... thought I'd share this, in case this could help.
it's a bit annoying combined with the view template compile issue in play framework. but my approach is to regenerate the eclipse project file and add view template path into the class path