I have a big java project. Using maven to automate the build and manage dependencies and JUnit for the unit testing.
When i'm running mvn clean install from Intellij the build fails because of one unit test that fails.
The test succeeds when ran manually.
Also, executing mvn clean install from the terminal succeeds. (all tests pass)
I'm not sure where to look for the problem here.
Thanks!
Related
I'm writing code in Intellij and have a JUnit test class included in a project and i understand that running of JUnit should always be done at build time.
Is there a way to first run the JUnit and only if there were no test error run the project itself ? I want them to run together with 1 click (NOT run them seperately/manually).
Also, i would like the above to work even when the project is packed as a .jar file.
How can it be done ?
Thanks !
In Intellij:
Run -> Edit Configurations
Create a JUnit configuration for your tests
Create a Run configuration for your project.
And on "Before Launch": Add -> Run Another Configuration and choose the one created at point 1.
It doesn't matter how your project is packed (jar, ...)
Normally this is done by using a build management tool like: maven, gradle, ant. In this way the build tool will run tests for you and stop if they fail.
With maven, it's just a command: mvn clean package exec:java which will compile code, build project, run tests and execute your code.
See example project: https://github.com/HaveACupOfJava/maven-jar-demo
I am trying to write unit test cases for an eclipse plugin. Went through http://www.vogella.com/tutorials/EclipseTycho/article.html#run-the-build-with-the-tests and created a eclipse-test-plugin.
So, the test plugin (let's call is plugin-b) has a dependency on another plugin for which the test is written (plugin-a).
When I run mvn clean install, I can see that tycho-surefire is trying to run the tests and in the process is trying to launch plugin-a. However, plugin-a requires a set of VM args to start correctly. Am trying to pass the arguments like below:
mvn -Dabc.properties=bridge\bundles\com.blah.blah.blah.blah.bridge\abc.properties clean install
but they aren't going through to plugin-a.
Any help is greatly appreciated.
Finally figured this out:
mvn clean install -Dtycho.testArgLine="-Dabc.properties=../../bundles/com.blah.blah.blah.blah.bridge/abc.properties"
That'll pass the system properties to the test runtime.
I am running maven like this:
mvn clean cobertura:cobertura package
I am noticing that my unit tests get run twice (thus doubling my build time). Is there a way to run cobertura AND generate the package in the same command without running tests twice?
An easy way would be to run two separate commands. In Bash it's then easy to chain them together into one line:
mvn clean cobertura:cobertura && mvn package -Dmaven.test.skip=true
The first bit:
mvn clean cobertura:cobertura
Does clean, runs the tests and generates the coverage report.
The second bit:
mvn package -Dmaven.test.skip=true
Does the packaging, but tells it not to run the tests.
The && is there so that if the first command fails, then it won't try to run the second.
I currently try to run an integration test with maven failsafe, like described in here: reference link .
For this, I got 3 Modules: datamodule, datamodule2 and testmodule (all covered by a parent pom). testmodule depends on the two other modules. It got an test in src/test/java/ named MyTestIT.java. If I try to run the test with mvn clean test failsafe:integration-test, everything runs fine, but if I only run mvn failsafe:integration-test, it does not work. Does somebody know how it's this way?
If I try to run the test with surefire, for example with mvn test -Dtest=MyTestIT, it says it can't find MyTestIT in datamodule, and I need to set -DfailIfNoTests=false. If I try to run it with mvn test --pl testmodule, it says it can't find the dependencies (this only happens when they are not installed, but I don't want to call install everytime I run a test).
Is there any way of setting this in a pom, either in the parent pom or in the project pom? Or any other way of saying to maven "only run the integration tests, use the right dependencies and do not install everything"?
I have a Maven project and I have included some unit tests. I can run those unit tests from command line using
mvn test -Dtest=AppTest
It will run the unit test (AppTest class) without any problems. But if I tried to run the test on Eclipse as JUnitTest, I got an error saying
"No Tests found with test runner 'JUnit 3'"
I know the test (AppTest) is not a JUnit test but I didn't see "maven" option if I right clicked on the test class.
Do you know how I could run the tests on Eclipse?
If those are testng tests, then you can download the eclipse plugin for TestNG and right click and run them as test class. Testng plugin here
If you want to run the command line way of maven, you would need the maven plugin for eclipse from here
Then you can right click your project and you should see an option of Run As -> Maven Test. You would need to set relevant arguments in the surefire plugin of pom or use run configuration to specify parameters like you did in -Dtest
I would suggest the testng plugin which would be simpler to just select the class and run the class or a single case or a package even.