I have a multimodule project that is dependent on a rather large thirdparty library/apis. It is not possible to run automated junit tests with the actual library, since the apis interact with a system external to the management of the dev environment. As a workaround, we created classes that mocked the interfaces/apis so that we could do junits. We use eclipse as our IDE for development, so to run junits, we simply move the jar up higher in the classpath, recompile, run our junits, and everything works great.
Looking for a similar solution now that we are moving to Maven. Basically, after building our code, need to rebuild all of it again using the mock jar to run junit tests. This goes across all modules of the application. I tried adding the jar in the test scope, but that is only used for compiling the test classes; the sources classes are still compiled with the real jar. However, it fails at runtime since our mock jar does not match all signatures of the real jar (so a hot swap of the jar doesn't work; making all signatures match would be large undertaking). So the source needs to be recompiled with the jar.
So it appears there are two options:
1) Make a standalone test module that somehow pulls in all the source modules code and recompiles it using the mock jar and runs the tests or
2) Each module creates a testjar in addition to its installable jar that compiled with the mock jar, is then used by the dependent modules during the test phase.
Please advise. Any examples of how to do either of the above would be greatly appreciated.
Check out this link. I think it has what you need. You can handle this using two maven profiles. According to this you can have different dependencies for each profile.
Related
Warning: I'm a huge noob to TDD and Kotlin.
I've found good code snippets on the web for writing JUnit tests in Kotlin, but when I copy and paste, IntelliJ does not automagically import kotlin.test.* or org.junit.Test. Typically in Eclipse, when I copy and paste code snippets like this, the IDE can figure out where these libraries are in my underlying java install. Figured Kotlin/IntelliJ would be the same.
In the below screenshot, any idea why I cannot import test libraries? Do they need to be added explicitly to my path? Do I need to put these under a test, rather than the src folder?
Thanks
JUnit isn't in your project classpath, so IntelliJ can't find it's packages.
Follow the steps outlined in this answer: Correct way to add external jars (lib/*.jar) to an IntelliJ IDEA project, choosing libraries and then junit.
So far I have been using eclipse to run testng tests, which requires me to code out a small program that includes a testng project; however this means every time I need to setup someone else's machine I have to pass alone the source codes so that they can run on their own eclipse.
I am sure it is not the best practice as when I was doing it in C#, I can build a .dll file to be imported in nunit's UI and I can execute the test from the nunit's UI. In this case I will just need to feed new users with the .jar or w/e file and tell them to use that UI tool to execute the tests. My questions fall below:
1) Are there any equivalent of nunit UI's for testng?
2) If so, how can I generate a .jar or w/e file of the testng project?
I wonder if someone can point me to a good tutorial/sample/best practices about using JUnit4OSGI with Equinox as the OSGI container?
I already downloaded JUnit4OSGI and started writing sample test cases, but what I'm looking for are answers for questions like:
1- How to structure the unit tests? put it in a separate bundle or each bundle should have its own unit tests?
2- How to run the unit tests using a maven plug-in? Or is there a better way?
3- How to run the unit tests during development as I understand there is a command line specific to Felix only.
Thanks.
I cannot help with Junit4OSGi but I can offer an alternative that works with Maven. It has the following parts:
testRunner: A module that can run tests if they are registered as OSGi services
testRunner-junit4: Junit4 engine for the testrunner module
eosgi-maven-plugin: A maven plugin that can use the modules above and run the unit tests during integration-test phase in equinox, felix or a custom container
richconsole: A simple module that makes it possible to drop modules to the OSGi container. Together with the maven plugin they can be used to update maven dependencies in the container without restarting it
Testrunner itself does not really care what technology offered the OSGi service. It could be blueprint, DS, iPojo or whatever. It needs the followings:
eosgi.testId service property must be provided. This is a unique value
eosgi.testEngine service property must be provided. In case of JUnit this is junit4
In case of JUnit, the class/interface must be annotated with JUnit annotations. Beware that blueprint wraps the service objects (I do not know if iPojo does it as well) so you have to implement an interface in your class and annotate the functions in the interface instead of the class
I think the best place to start is the maven usage site. At the moment the osgi-liquibase-bundle project uses the most up-to-date versions. Without knowing what it does, it is a good example of configuration (project hierarchy and pom.xml configuration).
All the modules and the plugin is available at maven-central.
Update
A guide about the usage of the tools is available at http://cookbook.everit.org
Update 2016.12
There is an Eclipse plugin now that allows the user to start/stop/debug/upgrade the OSGi environments specified by eosgi-maven-plugin. The usage of the plugin has benefits over the usage of richconsole.
Cookbook will be updated soon to use the Eclipse plugin instead of richconsole.
I'm in the process of building a Carbon Archive using the new WSO2 Developer Studio. I'm trying to work out how I can wrap the components (Sequences/Proxies etc) in JUnit tests. These tests will need to run as part of a CI build process (Jenkins) in order to detect errors with any modified code. I've done some research and can't seem to find anything that immediately stands out on how to achieve this. I did find this link https://wso2.org/jira/browse/TOOLS-855
which suggests that it hasn't yet been implemented. Can anyone confirm when this will be implemented or if there is any way at present to achieve this?
There is currently no straight forward way to implement this scenario and this feature will be supported in a future version.
One mechanism i can think is that, add a separate Test module as a part of the build which executes after building C-Apps.
So what happens in here is that, first Jenkins produce the CAR file for C-Apps. Then Maven start executing the JUnit test suite. Before the execution of Test Suite, you can configure maven to copy the CAR files to Servers and start up server. Then execute the Test Cases against the started up server.
This way you can deploy the new CAR files in your Carbon Server and execute the tests against the new configuration in the Server.
Thanks and Regards,
Harshana
I would like to use IntelliJ IDEA for development of JBoss Seam project. seam-gen is creating the project stub, however the stub is not complete. In particular it is not clear how to deploy such project.
First of all I had to define manually web project facelet and add libraries to its deployment definition.
The other problem was persistence.xml file. In the Seam generated project it does not exists, since Ant is using one of the persistence-dev.xml, persistence-prod.xml, persistence-test.xml files, changing its name, depending on deployment type (which is ok). Obviously I can create persistence.xml by hand, but it goes againts Seam way of development.
Finally I decided to use directly ant, which is not partucularly comfortable.
All these tweaks made me think that I am doing something wrong from the IntelliJ IDEA point of view.
What is the efficient way of configuring IntelliJ for usage with JBoss Seam (deployment, in particular)?
I am using JBoss Seam 2.1.1, Intellij 8.1.4, JBoss 4.3.3
facet
I don't think you have to create any facet manually, as long as i remember IDEA always did it automatically for me...
persistence.xml
If IDEA didn't grab automatically persistence-dev.xml, you can tell her to use this file and not care that it's name will change after deployment...
artifact
You can still build your app using ant and create an analogical artifact in IDEA in the same location (for example exploded-archives/Project.war) - just leave "Build on make" unchecked (you want to build this artifact with ant)...
deployment
now, when you create new run configuration for the jboss as, in the deployment tab you can choose your artifact... just as if it was built by IDEA