I am new to Karaf IT testing within the karaf container. I created a small practice project
Practice OSGI project. All the bundles are running fine as I am able to run them in karaf container(3.0.8) and able to make a rest hit to manually test it out. But Now I am trying to test it via integration tests. I wrote a testcase as well, but when I try to execute it, the maven says, no tests to build. Here my objective is to run a simple command like mvn clean install or mvn clean test so that it builds the complete project and in end test it using integration test(deploy karaf container, deploy bundles and execute the test cases, and bring the container down).
I hope I am able to explain my objective and question well.
Any help will be greatly appreciated.
Your test code is in the wrong directory. It is in src/test/main/java while it should be in src/test/java.
After this change the test runs but produces an exception. So there is more to fix but I guess this already helps you a bit.
Btw. I saw that your maven projects all have version 0.1 this is not a good idea in maven. You should always use a SNAPSHOT version. Release version should only be built and deployed once as they can not be overwritten in a remote maven repo.
Related
I tried running unit test on the play framework java starter example within intellij but it doesn't seem to work.
I downloaded the project and imported it into intellij via the SBT import.
When I tried running the tests from intellij I got "Class not found: "UnitTest"Empty test suite"
If I run the SBT test task, the tests are running and passing.
When I go bask to running the tests from intellij after running the SBT test task, the test run and pass.
It's like intellij is not compiling the project
I am working with intellij ultimate edition version 2018.2 and have the scala plugin (v 2018.2.11)
How can I make this work?
Edit (in respose to #hce)
I upgraded intellij to the latest version: 2018.3.2 (couldn't find 2018.3.5) but I still experience similar problems.
I started with a newly downloaded starter project.
import the sbt project:
Then tried to compile and got an error:
I managed to solve the compilation problem by configuring intellij to use the play2 compiler ("Use play2 compiler for this project")
I then tried running the tests and but intellij complains it can't find the class
this is the run configuration that was created by intellij. the class name (UnitTest) is marked red...
Is it any different in your environment?
Is there anything wrong in my process?
I tested it with IntelliJ 2018.3.5 and the Scala plugin. It works well.
So the cause seems to be in the configuration of your project.
It would be helpful if you can provide your run/debug configuration and the settings.
There are many reasons.
You could try the following...
Make sure you use java 1.8 as the project jdk.
Use sbt 1.2.1
Check your run/debug configuration.
File -> Invalidate Caches/Restart...
Build --> Rebuild Project
Run --> Edit Configurations / remove Junit / Apply and restart your test. A new Junit configuration is created automatically
Edit:
After the comments of #NirBrachel, the solution was to use the sbt-shell to compile the project. (I recommend clean, compile and test).
You could automate this during import:
Why?
Info: sbt compilation for play framework 2.x disabled by default
You can try to activate Play2 framework in the Settings...
WARNING: This settings didn't work for me, because it's not saved by IntelliJ.
I didn't find out yet why.
EDIT see this link for a possible cause.
I use Scala plugin and Play Framework. I can run tests in 3 ways:
simple run 1 test from IDE (but I can't run all tests in package by this way)
run tests from sbt
run tests with use this configuration (it's allow run tests with coverage):
Sorry for my English.
What I want to achieve is as:
Build the maven project and push the jar to repo, using maven & jenkins.
Deploy the application, using script.
Run jmeter test cases and display test results in jenkins dashboard.
First jenkins build my project and push it to repo.
Then I have defined a post build step in jenkins to run script on remote server, this script deploys and starts my application.
Then I have created a post build action in jenkins to invoke top-level maven targets, to run mvn verify, which triggers the jmeter-maven plugin, which runs the test cases on my already running application.
Is this a good approach and if not please let me know a better way to do this?
Thanks in advance.
The bit that may be missing here is how Jenkins knows if the build should be marked as passed or failed? Even if jmeter-maven-analysis plugin execution did exit with zero exit code, it doesn't mean performance-wise the application is fine. It may be, but don't have to be. I came across that kind of concerns some time ago and provided a solution. Check project wiki for usage example and more information.
We want to accelerate our build pipeline for a multi-module Java web application, which roughly consists of
compile/code analysis
unit tests
integration tests
GUI tests
At the moment each of these build steps starts from scratch, compiling and building again and again, which costs time and means that we do not deploy the actual files to production that have gone through the tests. Is it possible to get Maven to not recompile everything on subsequent steps but instead run the tests against the previously compiled classes?
We are using Maven3 to manage our dependencies and Teamcity as a build server (7 at the moment, planning to upgrade to 8 soon). I have tried to set up a build chain, doing a
mvn clean install
on the first step and then exporting all the */target/ folders to the following builds. Then ideally I would only do a
mvn test
mvn integration-test
Unfortunately I have not been able to persuade Maven to do this properly. Either it compiles the classes again or produces errors.
Has anyone successfully done this kind of setup and has any pointers for me? Is this possible with Maven and is this even the right way to do things?
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.
We are currently working on a distributed Java EE-Application and have therefore a separated test and production system.
Compiling and Bundling is done via an Ant-Task. Now we want to deploy the Jar-Files of the different servers to the test-servers and run the JUnit Integration / Function-Tests there. If they succeed, then the current version should be deployed to the live-servers.
Plain Unit-Tests are executed by Hudson.
Is that possible with Maven and is there any information or best practice available?
Yes. Hudson has maven integration. Take a loot this wiki and this link.
You can set unit test case thresholds for your job to see if it does not pass a certain number of test cases. In that the deploy plugin will not get invoked and the app will not get deployed.
Take a JAR built from Ant and reuse it. I would add a Maven repository to your environment such as Artifactory, Archiva, or Nexus and deploy to that using Ivy. You almost certainly need to use a Maven repository to be happy with Maven for anything other than small scale personal projects. http://ant.apache.org/ivy/
Use Maven to grab the JAR from the Maven Repository. For this, just use a normal Maven dependency declaration.
Run Maven on the QA server, with the JUnit tests declared in that project. If that succeeds, deploy the JAR to the production server. For this, the details depend on the production server. If it's a WAR, I would use Cargo, but if it's a JAR it really depends on what's executing the JAR - you might need some sort of file copy, scp, etc. http://cargo.codehaus.org/
Hudson and TeamCity both have deployment features as well. You just set up a job to run (in this case the Maven job) and tell the CI server to deploy on success.