I'm using Netbeans with Maven and TestNG. When running tests with the maven surefire plugin, I can setup some configuration parameters, in particular the logging level used for my tests (trace):
-Dorg.slf4j.simpleLogger.defaultLogLevel=trace
-Dorg.slf4j.simpleLogger.logFile=System.out
However, when running a specific test file (CTRL + F6) or test method ("run focused test method"), Netbeans does not use surefire (which is good) and therefore ignores those parameters.
Is there a way to change the JVM parameters used by Netbeans when it runs tests that way?
This is somewhat similar to this other post but my question is specific to Netbeans.
From the documentation of Netbeans 7.2 (see Netbeans 7.2 changes, section Maven) :
... Now Test File always runs Maven by default, just like Test Project ...
What version of Netbeans are you using? Probably you should just upgrade to 7.2.
In the Project Properties, you can create profiles under Run. In theses profiles you can customize VM Options. You can add your parameters here, create a Test config and Run config.
Set fork property in the surefire plugin configuration in Maven. This will start a new JVM. Now, the second part is how to read the JVM parameters that you want into the new JVM. Depending on what you want to do, you might need to be read them from the environment.
In my case i went to project/properties, then "Actions" category. There you'll find "Test file" and "Debug test" actions. Select them and place whatever properties you need in "Set properties" box.
Not sure if this is only applicable for Maven projects...
Related
I'm looking for an IntelliJ IDEA plugin that would run my tests each time I change my code. I looked for such a solution and I found:
Infinitest, which works, but is inconvenient because I need to add the facet to each module, and it opens a new tool window for each module (which means 15 tool windows for me).
Fireworks - didn't work for me, maybe it just doesn't work with IDEA 14 (in its repo I can see that last changes were made in 2009). IntelliJ also reports that it throws exceptions.
There are lots of ways I could run all my tests (including writing a simple script for this), but I'm looking for a tool that would be smart enough to rerun failed tests first, and that would understand module dependencies (so after a change in some module it would run only tests of dependent modules).
I prefer free options, but if there's something paid for a reasonable price, I would accept it as well.
IntelliJ now actually has a Toggle auto-testin the run dialog. Just run a run-configuration and then select Toggle auto-testin the run dialog.
It's not as intelligent as you would have hoped. It just reruns when it detects changes.
I know this is a 3-year-old question but I think it will help people who face the similar problem in future. So I found out a way to enable SBT style auto test execution in IntelliJ studio.
We need to do 2 things to enable auto test execution.
Enabling auto project build - This can be done in settings by going into File -> Settings -> Build, Execution... -> Compiler and selecting "Build Project automatically".
Enabling "Toggle auto-test" in run dialog box
This will start auto testing. Although this works fine, it takes time to build the project even when my project is tiny so for larger projects it will certainly take very long time to complete the build and execute tests.
Reference: Original article which explains these steps
If you are OK running tests which cover a single method chosen by you, you can try this plugin (it is continuos in the sense that you make changes to a method, then click on the method and the plugin will run all the unit tests automatically which cover that method): https://plugins.jetbrains.com/plugin/15063-unit-test-coverage-history-runner
You can use the Intellij Teamcity plugin. Teamcity is a paid product but there is a free version which gives you 20 projects and 3 agents for free .
It has a remote run feature using which you can send in unchecked code to run tests before committing.
It also has options to run failed tests first
Usage instructions for Remote Run
I have an existing project in Eclipse (let's call it "NotPlayProj") which has a lot of java code still under development. I made a new eclipse project using play 2.1.0 (let's call it "PlayProj"). My goal is to use code from NotPlayProj in PlayProj and have both Eclipse and the Play compiler notice changes in either project.
If I go into the properties for PlayProj and add NotPlayProj via the Project tab, then method completion and inclusion works within eclipse, but the Play compile doesn't see the result. I've looked at Play modules and those don't seem to do what I want.
Is there any way to do this, ideally without modifying the NotPlayProj?
Edit ---
I've looked at http://www.playframework.com/documentation/2.0/SBTDependencies which shows how to export a jar from NotPlayProj into the PlayProj/lib directory, but this requires a manual export for each time NotPlayProject changes. I suspect that the Managed dependency section is supposed to cover this, but I've never used SBT before and am therefore probably missing something basic.
What you need is continuous integration.
Have a look at Jenkins: http://jenkins-ci.org/
You should setup a Continuous integration server and customize the builds you need.
Example:
You have your PlayProj running in some server, it needs to be able to use some of the latest classes from the other project called NoPlayProj.
Rebuild is a must, things such as downtime zero are difficult to achieve(At least I don't think this is what you are asking for either).
The steps you need to automate with Jenkins are:
1 - Build and deploy the latest version of NoPlayProj which is located in some repositorium
2 - Build and deploy the latest version of PlayProj which is located in some repositorium and also is contains your last commit where you updated the dependency that exist with NoPlayProj
A not very complex build and deployment instructions can be configured in Jenkins. This should speed you up a bit.
Also another suggestion would be to mavenize both projects if possible, this will help you manage the dependencies easier.
Just to clarify one thing, you said: My goal is to use code from NotPlayProj in PlayProj and have both Eclipse and the Play compiler notice changes in either project.
Well the order in which you execute the builds will be dependent in what you want to do as long as you update the dependency before you commit the code.
One last thing, if you don't want to deploy you don't have to do so you can create the Jenkins jobs, in such ways that you only build. With Jenkins you can do a lot of stuff, also you could execute some help scripts of your own that can provide you additional functionality.
I hope this was useful.
To let Eclipse see changes in NotPlayProj when working with PlayProj, it's enough to change configuration of PlayProj. Properties-> Java build path -> Projects -> Add NotPlayProj as dependency.
There is no straightforward way to let Play compiler handle dependencies, until you package it as jar. Consider configuration of simple ant task (External tools configuration -> Ant build ), which will copy your jar file. Task can be triggered by pressing the key or button.
With managed dependencies, every time you made change in NotPlayProj, you have to manually rebuild it. To let Ivy/Maven put dependency in your local repository. After that Play will take latest snapshot from your local repository.
Both approaches requires some efforts. Maybe you can take a look at Python scripts, which run Play, maybe it's enough to extend classpath with NotPlayProj when executing play start
Though I've never used the play framework, I would think that there is a format that both the play framework and eclipse understand and that is Maven. Look at http://www.playframework.com/modules/maven-head/home
I get a:
Exception occurred executing command line.
CreateProcess
Cause by a too long commandline (too many libraries, too long path to the jars) when running from eclipse.
The only solution for me is to go to run as configuration... then create a configuration, remove all default dependencies and manually add only the things which are required, so the commandline does not get cut off.
I normally do this for jUnit tests.
This is a waste of time, is there a different solution?
thanks
If you're on java >= 6 you can use classpath wildcards.
That should be enough unless you have your jars scattered around the filesystem, which would call for some cleanup.
edit
If you're simply running junit tests with run as junit test in eclipse then you can define 'user library' and add that to the classpath. Haven't tested it though, and it might suffer from some limits on environmental variable length in windows, but i think that's the safest bet.
edit2
You can try this plugin mentioned in this answer. It worked on indigo, so i guess it will work on helios.
You can play around with forking settings - if you do not fork junit execution, you should be fine. However, classpath management in eclipse is a big mess - it does not separate production and test scopes.
Real alternative would be working maven build, which you should have, as eclipse is not a proper building tool - surefire plugin provides anough alternatives to overcome classpath environmen shortage.
How can I configure Netbeans to call Maven Failsafe to run a specific integration test?
I know the Maven command to do this is 'mvn -Dit.test=MyClassIT verify' I also know how to configure 'actions' in Netbeans Project properties.
My problems are:
Netbeans sometimes runs the action (and calls Maven), and sometimes just uses its own compiler and test runner. Don't know how to tell it to use which. Bizarre
Netbeans adds "Test" to the class name. Instead it should add "IT". But the bizarre part is that there's nothing in the action that defines this behavior. The action just passes the class name.
I don't want to override the normal Test File and Debug Test File actions, because I need those for normal tests. But custom actions only appear in the Project's 'Custom' context menu, and not for any individual file! So they're unusuable. It would also be nice if I could make toolbar buttons for them.
If the planets align correctly and Netbeans issues the right command, Maven is launched with correct settings, but the debugger doesn't work
Using Netbeans 7.1 and Netbeans Dev 201201260600
If you right click on a project, theres a 'custom' option with as only one child option 'goals'. You can use it to run custom mvn commands; also notice that old commands are kept, so you don't need to type it every time.
I am currently working on a small program that should comment out some code used for testing.
I want it to auto run before the compiler while compiling the release version and another program that will comment the code back in after compilation was over.
The program works the only thing I am missing is to add it to the build process.
Thanks to all helpers!
In Eclipse, right-click a project, choose Properties → Builders and click New. You can add an Ant script or a command line that Eclipse will trigger when building the project. You can also control the order of builders in the same dialog.
However, I agree with JB Nizet – there are many advantages to having Ant or Maven build your project.
Don't use Eclipse to build the release version of your app. Use Ant, Maven, or any other build tool that is much more flexible than Eclipse, doesn't need a GUI, can be scripted and used by a continuous integration server.
All of these tools should easily be used to include your pre-compilation and post-compilation tasks in the build process.
That said, you could just use a public static final boolean constant FOR_TEST, and include all your testing code in
if (TestUtil.FOR_TEST) {
}
You would then have just a single place to change in the code to have all the test code removed from the compiled version. No need for a complex Java program to do that.
Or you could let all the testing code in the released version, and activate it when testing using a system property, for example. This wouldn't even need any precompilation/postcompilation phase, and would probably have a negligible cost.