I have a project consists with multi modules - I use Maven. Each module has an integration tests. Within module tests shared the same container - currently I use TestContainers. But there is a problem with long launching container with mysql database. Sometimes it takes too long, and whole build project with tests lasts even several dozen minutes. There is possibility to launch one container, shared between submodule? After each execution by submodule, I will erase database and configure for new submodule.
I see there is something like org.junit.platform.launcher from JUnit, but I don't see so much documentation and don't know if it help me in some way.
Related
I have a maven project with multiple modules and submodules. Each of these modules and submodule runs several unit tests of their own. As we know, maven-surefire-plugin runs unit tests for each module separately in a new JVM.
Now, as it would often occur, I have some global configuration/setup I need to perform before running tests. This configuration/setup applies to almost all the unit tests across the modules (that means across multiple JVMs). By default, this setup now runs every time, that is, for each (sub)module. If this configuration is a little expensive, it adds a lot to the exceution time.
One such example may be setting up db (clean the db and set it up). If I have 100 modules, this setup would run 100 times.
Is their any good/elegant way of splitting such configuration so it only runs once for the whole project? Also, I do not want to send in any properties through the maven command with -D, and this is make this process completely command-independent.
Situation:
JUnit is capable of running multiple test methods/classes in paralell. We have a bunch of integration tests that use Arquillian. In these tests we use our maven-build war artifact as #Deployment and enrich it with a few test helpers.
Question
Is it possible to enable parallel testing for Arquillian tests? Are there restrictions? If it's not possible: Is there some documentation about that fact?
Concerns
I think running multiple tests in paralell might be problematic. We usually only use the same single deployment for all methods in a Test class. If i run multiple test methods in paralell, will the same deployment be used, or will each method try to re-deploy its deployment?. What if there are different deployments for different methods in the same class, which shall be executed in paralell? Does Arquilian manage this, or will this cause errors?
Why should it cause errors? Because the deployments always contain the whole application. All beans. All Services which might use resources (ports) and whatnot. For example, if multiple deployments want to register the same EJBs, the whole thing must go down the drain.
... right? Does Arquillian handle these problems (can't think of a way how it could)?
It's going to depend on your container. For an embedded container, it should work without an issue (assuming ports don't conflict for any listeners). For a managed or remote, you'll get inconsistent results.
I'm coming from a .Net background cutting my teeth on a Java project that is using Maven, Spring and Liquibase. Needless to say, this is a new bag of concepts and frameworks to deal with.
Tests won't complete:
My tests wont complete successfully because they fail when attempting to access a table within my database. They fail because that table doesn't exist. I see that I have many migration files in a Liquibase XML format within my project, but am looking at how to run them.
liquibase-maven-plugin not an option:
I see that others might use the liquibase-maven-plugin plugin, but in my case, the project does not have that plugin referenced in any the pom.xml, only liquibase-core. There are a handful of other developers that knew what they were doing that worked on this project in the past, given that they never referenced this plugin in the pom.xml file, I assume it was for good reason and I wont be stirring that pot.
SpringLiquibase?
They have a reference to to a bean that looks like this: <bean id="liquibase" class="liquibase.integration.spring.SpringLiquibase">, which after further research appears to do automatic data migrations,
GREAT!
....but how do I go about invoking it? Must my project already pass my Tests and actually be "ran" before this logic gets hit? If that is the case and my project must successfully build / test, then I apparently must run my migrations outside of this SpringLiquibase bean.
Should I be using the liquibase command line and if so, can I safely assume this is what the previous developers were doing to initially establish their database?
You are right that the SpringLiquibase setup should do the database update automatically, but it will only do it when the spring framework is started.
My guess is that your normal application startup fires Liquibase through Spring but the test framework does not. Perhaps they had not noticed it because they would tend to make the database change in the liquibase changelog files, then start the normal application for initial testing (which updated the database) then build and run the tests. Now that you are running the tests first, the database is not yet there.
Are you able to tell if your tests are trying to start Spring?
Even in cases where an application is using SpringLiquibase, I usually recommend configuring your project to allow manual updates using liquibase-maven-plugin, ant plugin, or command line because it tends to make a more efficient process. With that setup, you can add changesets and then run liquibase update without going through an entire application startup or even running your tests. You could set it to automatically run on test execution, but the update process is usually infrequent enough that it is better to avoid the liquibase update overhead on every test execution. It is still very helpful to include in your application's spring setup so that in QA and production you don't have to remember to manually update the database, it is just automatically kept up to date.
I have a simple game which consists of two projects: Client and server. Now I want to test if they interact correctly.
Setup is: One Maven-parent project, and server/client as child-modules.
I don't now how to test the interaction: am I able to start both project somehow (how exactly?) in junit tests, or integration tests? So that I can listen for one projects output verify it and send it to the other? Or should I go another way?
For integeation tests create a seperate pom add both projects as test dependencies. Then start the server using testng beforeclass hooks or the maven failsafe plugin hook before the test starts, and close the server after the test.
This sounds like a good case for an integration test. I would do it as follows:
create a third maven module called IntegrationTests
use a maven profile integrationtests and activate it with -Dintegrationtests
pull in the client and server modules as dependencies in the new module
write my integration tests using JUnit (#Before, #Test, etc)
As Evgeniy suggested, you could of course put the integration tests in one of the existing modules, whereas my suggestion is to split it out to a third module.
If you need help on how to use maven profiles for integration testing, just google around, or feel free to ask if you have specific questions.
Good luck.
Typically you start the server from test and send requests from the test emulating client behaviour and checking that server reponses are what you expect.
Currently, I am working on a new version control system as part of a final year project at University. The idea is to make it highly adaptable and pluggable.
We're using the OSGi framework (Equinox implementation) to manage our plug ins. My problem is that I can't find a simple & easy to use method for testing OSGi bundles.
Currently, I have to build the bundle using Maven and then execute a test harness. I'm looking for something like the JUnit test runner for Eclipse, as it will save me a bunch of time.
Is there a quick and easy way to test OSGi bundles?
EDIT: I don't need something to test Eclipse plug ins or GUI components, just OSGi bundles.
EDIT2: Is there some framework that supports JUnit4?
More recently, you should have a look at Pax Exam:
http://team.ops4j.org/wiki/display/paxexam/Pax+Exam
This is the current effort at OPS4J related to testing.
Here are some tools not mentioned yet:
I'm using Tycho, which is a tool for using Maven to build Eclipse plugins. If you create tests inside their own plug-ins, or plug-in fragments, Tycho can run each set of tests inside its own OSGi instance, with all its required dependencies. Intro and further info. This is working quite well for me.
jUnit4OSGI looks straightforward. You make subclasses of OSGiTestCase, and you get methods like getServiceReference(), etc.
Pluginbuilder, a headless build system for OSGi bundles / Eclipse plug-ins, has a test-running framework called Autotestsuite. It runs the tests in the context of the OSGi environment, after the build step. But, it doesn't seem to have been maintained for several years. I think that many Eclipse projects are migrating from Pluginbuilder to Tycho.
Another option is to start an instance of an OSGi container within your unit test, which you run directly, as explained here.
Here's someone who's written a small bundle test collector, which searches for JUnit (3) tests and runs them.
Spring Dynamic Modules has excellent support for testing OSGi bundles.
There is a dedicated open source OSGi testing framework on OPS4J (ops4j.org) called Pax Drone.
You might want to have a look at Pax Drone ([http://wiki.ops4j.org/confluence/x/KABo]) which enables you to use all Felix Versions as well as Equinox and Knopflerfish in your tests.
Cheers,
Toni
Eclipse has a launch configuration type for running JUnit tests in the context of an Eclipse (i.e. OSGi) application:
http://help.eclipse.org/stable/index.jsp?topic=/org.eclipse.pde.doc.user/guide/tools/launchers/junit_launcher.htm
If you need to test GUI components I've found SWTBot gets the job done.
Treaty is a contract(testing) framework that is pretty academic but has some nice ideas. There are papers that are published on it, and the people currently working on improving it.
The ProSyst Test Execution Environment is a useful test tool for OSGi bundles. It also supports JUnit tests as one of the possible test models.
For unit tests use the EasyMock framework or create your own implementations of the required interfaces for testing .
I think we met the same issue and we made our own solution. There are different parts of the solution:
A junit4runner that catches all OSGi services that has a special property defined. It runs these caught services with JUnit4 engine. JUnit annotations should be placed into interfaces that the services implement.
A maven plugin that starts an OSGi framework (a custom framework can be created as maven dependency) and runs the unit tests inside the integration-test maven lifecycle.
A deployer OSGi bundle. If this is dropped into your OSGi container a simple always-on-top window will be opened where you can drop your project folders (from total commander or from eclipse). This will then redeploy that bundle.
With the tools you can do TDD and have the written tests always run inside the maven integration-phase as well. It is recommended to use eclipse with m2e and maven-bundle-plugin as in this case the target/classes/META-INF/MANIFEST.MF is regenerated as soon as you save a class in your source so you can drag the project and drop to the deployer window. The OSGi bundles you develop do not have to have any special feature (like being an eclipse plugin or something).
The whole solution is OpenSource. You can find a tutorial at http://cookbook.everit.org
During the last couple of years Tycho - a new Maven based build system for OSGi - has become rather popular among the Eclipse Foundation. This framework also includes method to use Maven Surefire to test OSGi bundles in separate testbeds...
There are many ways to test OSGi components, I suppose. One way of doing the testing is to use Robot Framework. What I've done is made my tests with Robot Framework and have the remote libraries either installed in OSGi or have them talk to OSGi-test components through sockets and robot would talk to these modules and run tests through them.
So, basically your OSGi-modules should have interfaces that do something and produce some output. So, in my setup I had a test components that would make service calls to the actual OSGi-component and then there would be a listening-service that would catch the events/service calls (made by the module under test) and those results could be asked by the robot. So basically this way you can split a massive system in small components and have the system run in production/production like enviroment and have it tested automatically on component level or have some of the real components be tested in unison.
Along with others mentioned mockito is very handy to mock plugin dependencies(references etc). see https://www.baeldung.com/mockito-annotations
How about bnd-testing-maven-plugin?
It allow running JUnit inside a running container like Felix or Equinox.
If you used the BNDTools for eclipse this is very similar but just maven withpout eclipse and without a UI.
https://github.com/bndtools/bnd/tree/master/maven/bnd-testing-maven-plugin
also look at the effectiveosgi archetype for maven. This will give you a good starting point to build your project or just add tests.
https://github.com/effectiveosgi