How can I use Eclipse to debug tests driven by sbt? - eclipse

I have a set of test cases that I want to debug (step by step, reading values, etc.). How can I setup my sbt build so that I can hookup an eclipse debugger?

I found a way to attach the Eclipse debugger. To the Build.scala project settings I add the following options:
//required for the javaOptions to be passed in
fork := true
javaOptions in (Test) += "-Xdebug"
javaOptions in (Test) += "-Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=5005"
Then in Eclipse I can create a new Debug configuration (arrow next to the bug icon) of type Remote Java Application. There I can select Scala debugger (Socket Attach) and specify the port 5005.
Problem I now have is that I cannot set any breakpoints, but that's another question and might be related to the version of Scala IDE that I use.
Edit
Problems with setting the breakpoint had (most likely) something to do with the exotic constructions in my specs2 specification. I created a small object with a method in order to be able to set a breakpoint
object BreakPoint {
def set = {}
}

Using the Scala debugger through the remote connector works.
But if you want to avoid to go back and forth between sbt and Eclipse, you can load your project in Scala IDE using sbteclipse, and then run your specs2 tests from inside Scala IDE, in debug mode, using the JUnit launcher.

Related

IntelliJ: breakpoints in Scala tests won't get hit

I'm trying to debug a test in my Scala project.
IntelliJ runs the tests successfully, however the breakpoints in the tests never get hit.
The breakpoints inside the tested classes do get hit during the test, so I assume the problem is with ScalaTest.
As you can see on the screenshot, the breakpoints are set in various places in the tests, however IntelliJ won't recognize them, and simply finishes the debugging.
Is there any way to make IntelliJ to hit breakpoints in scala tests?
UPD1:
I do not run tests with sbt, I run them with Scala IntelliJ plugin, like this:
You could try the following:
File - Invalidate Caches/Restart... (within IntelliJ)
Remove the system/caches/* (look https://intellij-support.jetbrains.com/hc/en-us/articles/206544519-Directories-used-by-the-IDE-to-store-settings-caches-plugins-and-logs for location of caches)

Scala IDE + Play Framework - no breakpoint hit

I ran the Play Framework website using "activator -jvm-debug 9999 ~run" command as stated in the documentation and used "Remote Java Application" debug configuration in Scala IDE. From the Debug perspective, it looks it's connected.
However no breakpoint is ever hit. Is there a way to fix it, please?
The reason it didn't work was hidden in the build.sbt, the fork in run was set to true.
With setting
fork in run := false
the debugger works.
1st I would recommend to use simply sbt: sbt -jvm-debug 9999 run
2nd, you need to connect the scala IDE to the jvm process (never did in Scala IDE, just Intellij, but found this docs)
finally, there are some (rare) problems in more complex scala lines of code. Try to set the breakpoint in more simple lines (declarations of values for instance)

How to log commands issued from Intellij with Scala plugin to SBT

I worked some time with SBT and a text editor. Then, moved to Intellij, installed Scala plugin, and created a new project as in the picture here by choosing it to be based on SBT. Also, in the settings, I chose the SBT launcher to be custom, and made it point to the already-installed sbt.
I believe Intellij is probably calling SBT commands like sbt run and stuff in the background. My question: How can I see (a log of) these commands as they're called by Intellij to sbt and their responses? And as a plus: where can I edit them? I opened the "Edit Configurations" but couldn't find anything like sbt compile.
I believe Intellij shows the responses (e.g., [info] downloading...) below in the "Background Tasks", but
1. It doesn't log these responses and
2. It doesn't show the commands issued by Intellij to sbt.
Big picture/what I'd really want to do: have the IntelliSense features from Intellij and Scala plugin, but build and run from the terminal and not have any effects from Intellij on that.
The IntelliJ Scala plugin doesn't (yet) call sbt except for project import/refresh or if you have a run configuration that uses sbt. Compilation is done by the built-in compile server. If you prefer to use IntelliJ as an editor and run tasks from the sbt console, that usually works fine.
I don't understand the question well
do u want to see the SBT output? if you are using run/debug you will see both the command & the output in the run window (alt+4)
also intelliJ has a window called event log
I hope that help
Intellij reads the projects configuration from sbt and creates an equivalent configurations for its project format (either .idea folder or .ipr)
this is a similar question to yours but about maven, you may find helpful:
https://stackoverflow.com/a/30167052/2675679

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à

sbt & Play 2.0 Debugging Information Missing

I am using sbt to build my Play 2.0 project. I managed to configure sbt to open a debugging port, attach an Eclipse remote debugger and enter a break point. I put the break point into one of my actions. But when the execution stops there, I cannot inspect any variable. I guess that sbt builds the Scala code without debugging information.
Does anybody know how to configure sbt to add debugging information? Or could it be a problem of my Scala IDE plugin for Eclipse or anything else?
Many thanks in advance!
To start Play in debug mode via sbt, run:
sbt -jvm-debug 9999 run
I did not find a solution for all problems I have with debugging but at least it works so that I can use it. Here is my status:
I am using sbt directly and cannot use -jvm-debug 9999. But I added the following to JAVA_OPTS in the sbt launch script:
-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=9999
This gives the possibility to connect an Eclipse remote debugger and get debugging information (if running Play in development mode).
The problem that still remains is that I don't get the popups showing variable information when pointing the mouse cursor on a variable. But this seems to be a problem with the Scala IDE plugin and not with Play, because I get the variable information in the variables view in the debugging perspective.
I found this to be the easiest solution : (using IntelliJ IDEA )
in IntelliJ :
Go to "edit run configurations"
Create a new remote configuration (port 9999, all other details leave with default values)
Go back to IntelliJ and run the new debug configuration (don't forget to put a break point)
From command line run :
sbt -jvm-debug 9999 run
I had the same problem in a modularized sbt build. Adding
javacOptions ++= Seq("-g")
to the build.sbt file, solved the problem of missing debug information in the compiled classes.