set scala breakpoints when creating library and testing using sbt - java

I have a library I'm creating using Intellij. I am doing TDD with ScalaTest and SBT to run my testing library. I want to set a breakpoint in Intellij for when it runs my tests to stop at a particular line so I can do inspection. How do I setup the run configuration to do this? When I extend my library class to extend App to give it a main method it doesn't even allow me to add it as the 'Application' run configuration in Intellij. I don't actually want to have that as a run configuration, I just want to be able to set breakpoints.

IntelliJ has a module to test scalaTest classes. Just right-click on the name of your class, and click on Debug in ScalaTest (the first time around, you should have a dropdown on Debug to select how you want to run it).

Related

IntelliJ No Run Button upon right click

I have a series of automated java tests as part of a maven project in java. I have just switched machines from a machine where the tests run fine.
Now, when I right click on the test java class, there is no 'Run', 'Debug' options. Only the main option at the top of the window - which doesn't work either.
I have checked the Junit plug in is installed and I have Invalidated Caches and restarted.
Any ideas?
Thanks
You need to "edit configuration" and add run configuration for your test class.
Here is the example for JUnit but for TestNG it should look similar. You expand the combobox on the top right and choose "Edit Configuration..". Then you add JUnit/TestNG configuration and in configuration details specify the test class to run.

Can't get ActiveJDBC dynamic instrumentation working with IntelliJ IDEA run configuration

I'm trying to use ActiveJDBC's dynamic instrumentation with the -javaagent command-line option in the run configuration of a JUnit test in Intellij IDEA (2018.1 Ultimate). I've entered the following in the "VM Options" input field of the run configuration dialog:
-javaagent:"C:\Users\cschabli\.m2\repository\org\javalite\activejdbc-instrumentation\2.0\activejdbc-instrumentation-2.0.jar" -Dactivejdbc-instrumentation.log=true
After starting the unit test, I get log messages of the ActiveJDBC instrumentation agent like these:
ActiveJDBC Instrumentation - You are using dynamic instrumentation
ActiveJDBC Instrumentation - Found model: foo.bar.MyModel
But when the application code accesses the model class, I get this error message:
org.javalite.activejdbc.InitException: failed to determine Model class name, are you sure models have been instrumented?
Why doesn't this work in IDEA?
I used you configuration on a project ActiveWeb - Simple:
pretty much using your configuration. All worked as expected, see the screenshot.
However, Dynamic Instrumentation has its limitations with Java8 Lambdas.
If instrumentation is annoying and gets in a way, you can configure a simple script like this as an "External Tool" in Intellij Idea:
#!/usr/bin/env bash
## This script will instrument fast without Maven
## Adjust versions on the classpath if upgrading!
export JAVALITE=2.0
export CLASSPATH=~/.m2/repository/org/javalite/activejdbc-instrumentation/$JAVALITE/activejdbc-instrumentation-$JAVALITE.jar
export CLASSPATH=${CLASSPATH}:~/.m2/repository/org/javassist/javassist/3.18.2-GA/javassist-3.18.2-GA.jar
export CLASSPATH=${CLASSPATH}:~/.m2/repository/org/javalite/activejdbc/$JAVALITE/activejdbc-$JAVALITE.jar
export CLASSPATH=${CLASSPATH}:target/classes
java -classpath $CLASSPATH -DoutputDirectory=target/classes
org.javalite.instrumentation.Main
This is what I'm using personally. This script avoids Maven startup delay, and executes in less than a second on a project with more than 100 tables!
I configured it to start by default before any JUnit test.
Feedback from Jetbrains:
For Gradle projects you can tell IDEA to delegate IDE build/run actions to Gradle (see option Preferences | Build, Execution, Deployment | Build Tools | Gradle | Runner | Delegate IDE build/run actions to gradle).
For Maven projects there is currently no solution. They have filed the issue IDEA-195924.
I found a way around this problem for Gradle, IntelliJ.
Instead of running from the green arrow on the top, go to
Gradle (in the right of screen) --> Tasks --> Application --> run
This one should work, as instrumentation happens properly with this run.

IDEA Play 2.4 junit test without full sbt build

I want to run JUnit tests for my Play 2.4 application within Intellij IDEA 14.1.4 to leverage full JUnit integration.
The tests are executed fine when I create a new JUnit run configuration. However on every test run a full SBT build is executed delaying the tests for around 30 seconds.
If I remove Make form the pre-launch steps in the JUnit run configuration the tests are executed directly without a full sbt build but then any code changes in test and application code are not picked up by IDEA. Even when the play is running with auto-compile on file changes IDEA doesn't pick them up for the tests.
Edit 07/09/2015
I've also exchanged Make with an SBT Action test:compile which only opens up a SBT console loading the project and stops with a prompt. It's not executing the action test:compile and therefore not starting the test at all.
What do I have to change in run configuration and/or project settings to get a fast and seamless JUnit integration for Play projects in IDEA?
Finally found the answer myself when digging through issue tickets of idea-sbt-plugin.
Exchanging Pre launch Step Make with SBT Action test:compile was the right way to go. However the SBT Plugin expects the default sbt shellPromt >. Play projects however define their own custom promt as [projectname] $.
I had to add the following line to build.sbt to get the SBT action to work.
shellPrompt := (_ => "> ")

Eclipse plugin to run specific method

I am making plugin in Eclipse that would run selected method with specific parameters (right click on method in package explorer and choose "Check" runs selected method with specific parameters and shows results).
What would be the best way to run selected method without having to compile whole project and use reflection (as project might not be complete and might not even compile yet)? I will also have to use EMMA.
Take a look on JUnit plugin and create similar implementation. I believe that it provides almost what you need except the fact that it works with JUnit tests only.

Integrating eclipse's hot deploy to also run unit test automatically, without performing maven install

I have set up eclipse to work just as I want with my java web app using the following instructions : https://stackoverflow.com/a/6189031/106261.
Is it also possible to get unit tests to be run as part of the auto build, without running a maven install (or test). So I make a change to a class, the tests get run, and if a fail occurs I get a some sort of indicator. Without needing to manually run maven test.
There are several ways to achieve this, all with their own limitations:
You could set up a CI server which builds your project every time you commit a new version. Very reliable but not really "real time"
You can add your own builder to the list of builders (project properties -> Builders), for example an Ant builder which runs "ant test" or something. This builder gets invoked every time you save. Every time. That means Eclipse will become a total slug unless running your unit tests takes less than a few milliseconds.
You can use one of the plugins mentioned here: Is it possible to run incremental/automated JUnit testing in Eclipse?

Categories