Unit test only fails in maven, not iIntelliJ - java

I'm hitting a weird issue were my unit tests fail when running mvn install but they pass when running in IntelliJ.
I've looked at posts online about debugging maven, but I don't want to debug maven itself, or a maven plugin. I want to debug my unit tests when they have been called by maven. More specifically, I want to debug my code but using the Junit tests as an entry point for the debugging via a breakpoint.
Hope that makes sense.
My issue is relating to using introspection to look at some classes the application is importing from another project. This succeeds when the project is running or running in debug mode, but fails when maven runs the tests as a part of an install. i.e. the code doesn't find the classes in the other project when running under maven...
As this application uses multiple maven projects that all need to be installed, I've had to move my unit tests out into another project just so that the installs don't fail and I can carry on development.
However, for obvious reasons I would like to put my unit tests in each individual project, so am very keen to debug this and find out what is failing.
My project is called infinite-state-machine and can be found here - https://github.com/museadmin/infinite-state-machine
The unit tests are currently in their own project here - https://github.com/museadmin/infinite-state-machine-test
If anyone can advise me how to run maven in debug mode and attach IntelliJ to it so that I can set a breakpoint in my failing unit tests I will be forever in their debt :)
Thanks in advance for any help.
Brad

Related

Does infinitest for IntelliJ IDEA honor the run tests settings in Gradle?

I have a Gradle project that I would like to use infinitest with. However, while all test pass using the Gradle test runner, many fail in infinitest. Is this because infinitest uses the IntelliJ test runner to run the tests?
I expect this is the case since I get similar results when I try to run tests manually using the IntelliJ test runner.
How can I configure infinitest to use Gradle as the test runner?
Infinitest starts a new JVM to run tests, it gets the project classpath from IntelliJ but does not know it is a Gradle project.
I don't know what the Gradle test runner does differently but it would be great if you could open an issue on the Infinitest bug tracker with the steps to reproduce the problem (ideally with a sample project).
In case the issue is with missing JVM options you can set them using the infinitest.args file

What does the "Maven Surefire plugin" means when it test your build?

I am working on understanding Maven and I'm learning about building your Java app with it.
So when I do a :
maven package
It does build my jar as expected but I see in the output console that Maven does build tests (it always say that the test a run and there are no failure).
I researched on the web about that and learned that Maven use a plugin called Maven Surefire. But I can't understand what does that plugin do to my code, what does the tests "means" ? What does the tests do with my code and how it works behind the console ?
The Maven surefire plugin runs the tests you have written. These are usually in the src/test/java folder. If you have none, the plugin does nothing.
Is this only one question? :D
So. Different things are going on.
You create an application with Java. To test the single components / packages / classes that you create most people use JUnit or TestNg. You usually have dedicated test classes that verify your production code behaves as intended without you clicking through all the things on every change.
When you now use maven to run your build the pom.xml file defines a packaging - in your case "jar" since you create a jar file. The packaging defines what set of default plugins run in the defined maven phases. You probably recognize package here. Maven executes all phases up to package and the registered / configured plugins.
To execute those tests maven provides the surefire plugin which supports running JUnit or TestNg tests. If you follow the directory conventions your tests reside in src/test/java and the surefire includes naming convention maven will execute those tests in every build (as this is the best practice). If you also want to write integration tests then there is the failsafe plugin. That plugin is not enabled by default and runs in different maven phases.
So the tests just run your production code - in fact they just do what you implement in the tests. They don't alter it in any way.
The maven introduction documentation has step by step explanations: Maven in 5 Minutes and the Getting Started Guide.
Starting from scratch this is probably a lot. So don't rush this. The build setup and test setup are very important things to have.

Java - Maven Test/Unit Test passed when running the whole package but failed when running the test individually

I just received a project from my collage and when I run the whole project with Maven test/ Maven install by right click to the whole project and choose Maven test or Maven install, it runs successfully. However if I run an individual test, this test failed. I do not really understand here why it happened. Can anyone give me a hint please? Thank you!
It is possible that another unit test is establishing some state that is affecting the unit test that is failing. It is best practice to avoid writing unit tests that depend on shared state, as there is usually no guarantee as to what order the tests run in. See this article for a good explanation of unit test best practices.

TFS and TestNG - Possible to Execute TestNG test(s) within TFS2015?

TFS and TestNG - Possible to Execute TestNG test(s) within TFS2015?
I have uploaded a Java Maven project to a Repo in my instance of TFS.
My java Maven project comprises of TestNG Test / classes
I can see that there is a Maven plugin within the TFS which also has a JUnit link.
4. I cant see any option to enable me to execute TestNG tests within the TFS, is it even possible?
It's able to use Maven task to build a Java application or test the application including TestNG test. Detail steps please refer this tutorial: Get started testing Java applications with Visual Studio Team Services
For test result report just follow juherr's reply in this question.
Yes you should be able to run your TestNG tests.
I think its eventually going to be Maven that is going to be executing your tests.
Maven makes use of surefire-plugin to basically execute your tests. For TestNG here's two of executing tests via surefire-plugin
If your test matches the default pattern "/Test*.java", "/*Test.java", "**/*TestCase.java" (See here)
Create a suite xml file for TestNG (See here) and have surefire plugin refer to it (see here).

Measuring integration test coverage with Maven

The followings are ok now:
I have a multi-module project in maven with EJB and WAR projects
I want to use JMeter (and later selenium) for integration testing. I can run both from Maven. The JMeter plan is ready, I run it with Chronos maven plugin.
My application is a Java EE application, so I want to test the code with the planned production aplication server, which is Glassfish 2.11. I can create/start/deploy/stop and anything like that with glassfish maven plugin
I have put jmeter and glassfish related build settings into a submodule in maven, which is dependent on all of the other modules, so in build lifecycle it is the least, and for this reason a good point to test the whole application
My problem is, that how can I reach the followings:
deploy NOT instrumented code, but run integration tests on instrumented one
how to get coverage info from application server
I wanted to use emma4it which was created to instrument artifacts. It would be good for me, but i cannot make it instrument the war file in the other submodule. I do not even know anything about the supported arguments of emma4it, since I did not find it at all (just a binary in repository), no documentation and no source (I know I can decompile it)
I want to have a coverage raport at least in maven site, but the top would be to have it in Sonar
Could you give me advice, how to do this? I can provide POM snippets if you need it.
FINALLY. The solution arrived. See at http://www.sonarsource.org/measure-code-coverage-by-integration-tests-with-sonar/?utm_source=feedburner&utm_medium=feed&utm_campaign=Feed:+Sonar+(Sonar)&utm_content=Google+Reader
I currently try to do it.

Categories

Resources