Intellij 13.0.2 JUnit test do not run in Debug - junit

Intellij 13.0.2 JUnit test do not run in Debug
I have created several JUnit tests that run fine in Intellij, but when I try to Debug the same test, the files build and the test is not executed. I look in the event log and all it says is All Files are up to date. It does run NMake, but nothing more.
I don't know if this is related, but the View | Tool WIndows | Debug is disabled.
What do I need to do to Debug JUnit tests?
Thanks

Select Run --> Run Configurations... from the IntelliJ window
Select JUnit on the left side.
On the right side there is a "Before Launch:" section for configuring the behavior before launching JUnit tests.
See also the help page for this.

Related

2 variants for JUnit execution: TestRunner & JUnitCore

There seem to be two approaches for invoking JUnit tests from the OS command shell:
java junit.textui.TestRunner <class-name>
and
java org.junit.runner.JUnitCore <class-name>
When do we use one versus the other?
Also, are there other ways to invoke Junit tests from the OS command shell?
JUnitCore is an entry point of JUnit - so if you want to run a test programmatically or of from some non-java script, I think, its the way to go for JUnit 4.
TestRunner is something a very old junit 3.x
Notice, that nowadays JUnit 5 is the latest available major release and it has yet another way to run the tests.
The question about different ways of running the tests from command line has been already answered Here so I can't add much to this.
However, I can comment on:
Also, are there other ways to invoke Junit tests from the OS command shell?
Nowadays in regular projects people do not run tests like this, instead they use one of build tools (Maven, Gradle for example) that among other things take care of tests.
So for example if you use maven, you can run mvn test and it will compile everything you need, including source code of tests, will take care about all test dependencies and will run all the tests with the help of build-in surefire plugin.
If you don't want to compile anything (assuming that all the code has been already compiled and all is set, you can use mvn surefire:test)
These build tools are also integrated with CI tools (like Jenkins, etc.) So this is considered to be a solved problem.
So unless you're doing something really different (like writing the IDE UI that should run test selected by user on demand or something) there is no really need to run tests with the options you've mentioned.

How would I run integration tests from vivet/googleApi?

I am trying to work out how I would integrate this shared library from GitHub into my code, since it is a shared class library, for starters I just want to run the integration tests, but I cannot work out how go get the test runner to run them.
I created a console application in my main project and a reference to the GoogleMapsApiTest in the console but I am not sure how to call the tests from there to run them.
GoogleAPIClassLibrary
I had to download the gui test runner and build it from GitHub. Link to project
now I can at least run the tests, I am still not sure how to use the library but that should help at least see how it is supposed to work.
I was able to run the unit tests by downloading the NUnit source code at the link in my post and then browsing to the output dll of the class project, to load the tests apparently the gui-test runner is no longer available for download, so hopefully that will help someone else out if they run into a need for running tests in NUnit.

Forcing Eclipse to run JUnit tests in the same order that Maven runs them

I’m using Maven 3.2.3, SureFire 2.17, JUnit 4.11 and Eclipse Juno on Mac 10.9.5. I notice that when I run my JUnit tests via the command line
mvn test -Dtest=MyTest
the individual tests within the file “MyTest.java” run in a different order than when I run them in Eclipse (by right clicking the class name and selecting “Run As -> JUnit Test”). How do I get Eclipse to run the tests in the same order in which they are run on the command line?
Thanks, - Dave
The order of JUnit test runs are not guaranteed by design, as is mentioned in the JUnit FAQ page.This is done to promote the concept of test Independence, this will make sure that the tests will test their cases clearly and independently, and also ease maintainability.
This means that when you are running the tests in Eclipse, the orders are not guaranteed and keep changing. It's explained in "Can I change JUnit execution order?" on how you can possibly fix the order, even though its not a good practice.

Run Test Suite in Play 1.2.4

I am unable to run JUnit test suites in 1.2.4 since the command play test-only is not available. Please respond to the same in case there can be a fix for it without upgrading to higher versions of Play.
You can run your tests using the command:
play test
More information can be found here: http://www.playframework.com/documentation/1.2.4/test
Run your app in test mode:
play test
Then open the following URL:
http://localhost:9000/#tests
You'll be able to all, or individual, test classes to run. Unfortunately there's no way to run an individual test.
IDE:
If you are using an ide like eclipse you can run your junit tests from within the ide.
Command Line:
There are also the following two options for the command line:
Option 1:
play test
This runs the app in test mode. You can then run all tests via a browser interface available at:
http://localhost:9000/#tests (or your custom port if you changed it)
Option 2:
play auto-test
Runs the tests automatically without opening the browser.
Try using testOnly as the command, instead of test-only.

Hudson + JUnit + embedded GlassFish, how to provide domain configuration?

I'm using NetBeans and GlassFish 3.0.1 to create an EJB3 application. I have written a few Unit Tests, which get run via JUnit and make use of the embedded GlassFish. Whenever I run these tests on my development machine (so from within NetBeans), it's all good.
Now I would like to let Hudson do those tests. At the moment it is failing with lookup failure on a resource (in this case the datasource to a JPA persistance unit):
[junit] SEVERE: Exception while invoking class org.glassfish.persistence.jpa.JPADeployer prepare method
[junit] java.lang.RuntimeException: javax.naming.NamingException: Lookup failed for 'mvs_devel' in SerialContext
After searching around and trying to learn about this, I believe it is related to the embedded GlassFish not having been configured with resources. In other words it's missing a domain.xml file. Right?
Two questions:
Why does it work with NetBeans on my dev box? What magic does NetBeans do in the background?
How should I provide the file? Where does the embedded GlassFish on the Hudson-box expect it?
Hudson is using the same Ant build-scripts (created by NetBeans).
I've read this post about instanceRoot and the EmbeddedFileSystemBuilder, but I don't understand enough of that. Is this needed for every TestCase (Emb. GF gets started/stopped for each bean-under-test)? Is this part of EJBContainer.createEJBContainer()? Again, why is it not necessary to do this when running tests on NetBeans?
Update
Following Peter's advice I can confirm: when running ant on a freshly checked out copy of the code, with the same properties as hudson is configured, the tests get executed!
10-1 it is a classpath issue as IDE's tend to swap paths in and out depending if you run normally or unittests.
Try running the tests on a commandline from a freshly checked out version from your SCM. Chances are you'll have the same error. Debugging on your local machine is a lot easier than on a remote machine.
When it builds reliably on the command line (in a separate directory) then it is time to move to hudson.