how to configure java junit with Teamcity? - java

Can somebody please tell me how to integrate java JUnit with TeamCity?

You can use the jUnit task in your Ant script that you have TeamCity run.

Current Teamcity version doesn't provide separate JUnit build step.
I guess it's because of test classpath determination problem.
You may provide classpath explicitly with ant junit task.
Or Teamcity can fetch test classpath from IDEA or IPR project. These two links explain how to run junit tests as part of compile build step.

Related

Use Karate framework with Fail Safe and Sure Fire plugin [duplicate]

Is there a way to run Karate test during maven's integration test phase? It seems that surefire plugin is hardcoded into Karate. I have tried to override it using failsafe plugin but with no luck. I don't want test to run along with unit tests.
Thank in advance!
It seems that surefire plugin is hardcoded into Karate
I'm not sure where you got that impression, but no, the surefire plugin is not hardcoded into Karate.
Keep in mind that the simplest way to not run a JUnit test via surefire is to not use the *Test.java naming convention.
I think the solution for you is simple, whichever JUnit test is the "entry-point" for your Karate tests (the parallel runner is recommended) - just use the failsafe naming conventions.
And then, just include the failsafe plugin as per the examples and it should work. If you have trouble getting that to work (unlikely), then you should look at maven profiles.
EDIT: also see this comment: Is there a way to run Karate tests as an integration test suite against a pre-booted spring boot server?
Turns out that I cannot be done and it is a limitation of Maven, not Karate. Howto add another test source folder to Maven and compile it to a separate folder? - Here is my test project to prove it out: https://github.com/djangofan/spring-boot-hello - Thanks for leading me down what appears to have been the correct path to discover the limitation. Using Gradle would likely solve my issue but that is not an option on my project. If I use Karate for "separated integration tests", I need a separate mvn test module.

Cucumber tests are being skipped

I am using cucumber framework in my project. So for the reporting part, i need have started building the cucumber reports with jenkins.
So during the setup for the trail build i am facing the below issues.
All the tests are skipped, but not executing.
Can anyone have solution. I am happy to provide any other inputs required.
When using maven and cucumber you have two options to run the tests.
With maven: mvn clean install
With cucumber:-Dtest=Runnerclass test
Where Runnerclass is the class name of runner.
Include surefire plugin in your POM.xml to pick your test. if you want to run test as well, then use mvn clean install.
Refer
How to run Cucumber JVM Test in Jenkins

What is the process with Maven project to compile and test the code?

I have maven project imported in my eclipse. Now I need to start making changes to it and test it with the integration test (out of App server). Currently, the integration test is run out of server using openEJB container.
My basic question is, what is the regular process to compile, build and test with Maven?
mvn install
Maven -> Update Project.
Run my test from command line
Is it how it is done? I am specifically interested in knowing mvn install commands.
So should I do all three steps before I can test it?
Example: I just wanted to print something and see what is the output. For this I guess I need to do all these steps?
The openEJB container needs classes so it can load them.
There is a wonderful Maven quick-reference sheet at http://maven.apache.org/guides/MavenQuickReferenceCard.pdf
First, you should be aware that unit tests and integration tests are separate and are run from separate plugins and at separate parts of the maven lifecycles. Unit tests are run with surefire and integration tests are run with failsafe.
You want to run integration tests and the failsafe documentation says:
NOTE: when running integration tests, you should invoke maven with the (shorter to type too)
mvn verify
rather than trying to invoke the integration-test phase directly...
This is the best way to run integration tests directly in maven. It will run all the preceding steps necessary (eg: compile) in order to run the integration tests. It won't waste time doing an install because install happens immediately after verify.
But if you're running the tests locally, it may be a better idea to run your integration tests directly in your IDE. That will give you a much faster feedback loop.
If it is Eclipse project the most reasonable thing is to do everything not from command line but from Eclipse. Assuming you have m2e plugin installed, go to your_project->run as->Maven test and run it.
You dont need neither install nor package phase to run Maven tests, package will create a jar which is not needed for tests, install will copy this jar to local repo which is also useless. When Maven run tests it uses compiled classes from target dir and ignores project's jar if even it exists.
Yes, mvn isntall is the most popular option. It compiles, packages and tests your project.

Specific JUnit Test Faliure in a IntelliJ Maven Project

I'm working on a java project using IntelliJ. The project requires the use of some external libraries located in directories outside the project. Most of the code has been written by another author, I am simply expanding the functionality of the current program. The problem comes from one of the test cases for one of the external libraries (which was written by the original author). While these test cases pass successfully when I use -mvn test command in terminal, they fail when run in IntelliJ.
The error/failiure output is as follows
java.lang.Exception: No runnable methods <13 internal calls>
for all 15 tests
I've checked to make sure that the #Before annotation is before any #test annotations tests, and all the required tests have the #Test annotation before them.
Why would JUnit tests fail to run when they run and pass succesfully with the Maven Surefire Plugin?
I am using junit 4.1.
Your help would be greatly appreciated.
Ah problem solved. Quite a while ago actually. In IntelliJ, sometimes you need to set up VM Options with the -Djava.library.path = /(path to your lib files)/ as well as configure Environment variables by creating a variable --> LD_LIBRARY_PATH = /(path to required .so files)/
All tests run fine now.

maven and unit testing - combining maven surefire plugin AND testNG eclipse plugin

could you please share your way of unit testing in eclipse ? Are you using surefire plugin, m2eclipse & maven, or only testNG eclipse plugin ? Do you combine these alternatives ?
I'm using testNG + maven surefire-plugin and I had been using the testNG eclipse plugin a year ago so that I could see the results in testNG view. Then I started using Maven, but when I do "maven test phase" using m2eclipse, there is only console output and surefire reports that I can check in browser and to choose what test suite, test, or test method can be set up only via testng.xml.
On the other hand, if you use only surefire plugin and you have some specific settings regarding classpath etc., that you rely on, then running tests via testNG eclipse plugin doesn't have to be compatible with your code. Using surefire plugin, the classpath is different - target/test-classes and target/classes - than using testNG plugin, that is using the project classpath.
How do you go about what I was just talking about?
Is it possible to synchronize "maven test" using m2eclipse and surefire plugin WITH testNG eclipse plugin and view ?
EDITED: I'm also wondering, why the Maven project ("Java build path") output folder is target/classes for src/main and src/test whereas surefire plugin makes two locations target/test-classes and target/classes
Thank you very much for your your opinions.
Lisa,
You can configure the TestNG Eclipse plug-in to "watch" a test-output directory. Point it to target/surefire-reports and you should see your TestNG view update itself a few seconds after a Maven build terminates.
I see two advantages of using the surefire plugin:
Relying on the eclipse plugin only
works that way when everyone in the
project uses eclipse
Surefire plugin
can run from build that are done from
the continuous integration server
("jenkins")
And then if you have larger more long running (performance) test suites, you probably don't want to "block" your IDE while they run.
I don't think it is true what you say with the different runtime classpath, I just checked myself both maven classpath and the one when test is run via testNG eclipse plugin and both are the same. I think that m2eclipse plugin takes care of it. It's the same even for junit testing.
So afaik, there is no restriction for using testNG eclipse plugin for development and surefire plugin for instance for continuous integration as Heiko Rupp mentions. At least I have never gotten any troubles with it.
Just use both as you like, cheers !

Categories