I'm going to try to phrase this so that it is not an opinion based question. I have been doing some reading into other Maven questions and I do not think this is a duplicate, but if it is, please point me in the right direction.
I am writing a series of WebDriver JUnit tests to test the front end of my institution's web page. The tests are also configurable so as to be used both for regression testing as well as testing new features as they get added to the front end. Essentially module is executed based on the user's selected preferences which will create custom configuration options and custom scripts to execute the tests and then ultimately runs the scripts.
My project is using Maven to manage the dependencies, but was originally using Ant to execute the module and then generate the JUnit report. The question is if Maven would be able execute the project in a similar manner to Ant, as well as be able to generate the JUnit reports (or something equivalent).
Many thanks.
There is a maven-selenium-plugin that can be used to run Selenium tests and maven-failsafe-plugin can be used with it to generate your results. If you would like to see an example in use you could search for "stests" in Rice's pom.xml.
Configuration of properties in your tests can be handled in a variety of ways, I usually make use of System properties and/or property files. Dynamically configuring which tests to run I haven't found a solution I am happy with.
Related
I'm exploring the use of maven archetypes to generate a starter project. What I'd like to do is prompt the user for input, and then do something with that answer. I know it's possible to prompt for additional properties using archetype.properties. Is it possible to take the input from these properties and do custom processing of the project structure during project generation?
Specifically what I want to do is include or exclude sample code from a starter project. Some people will want to see a working example and then delete once they're ready to start, while others just want to get started with a blank project.
There are some open issues against the Maven Archetype plugin which (I think) relate to your use case:
https://issues.apache.org/jira/browse/ARCHETYPE-424
https://issues.apache.org/jira/browse/ARCHETYPE-274
These have been open (and largely inactive) for a long time, so they don't appear to be likely candidates for completion.
In the absence of built-in support for your use case and assuming there are just two possible outcomes (1. exclude sample code, 2. include sample code) then perhaps you coud provide two archetypes?
Alternatively, you could provide a single archetype and include a link to sample code (hosted elsewhere, perhaps on GitHub if the sample code is to be freely accesible) in a readme in the root of the generated project.
I am working on a project and using Maven to build it. The project is a quite big Java web application and it is supposed to work with both Mysql and Oracle databases.
The problem is that there are some specific annotations related to either of the two databases in the source code, plus some other differences, so that I am forced to manually comment/uncomment part of the code before building the application for one of the two databases.
Basically what I would like to achieve is to have my build script, maybe via a Maven profile, to automatically switch the source classes before building depending on the database I want my war to work against.
Putting it simply, the idea is to have MyClass.oracle and MyClass.mysql, and depending on my build profile I should move one of the two in the source dir, rename it MyClass and build. This should be done for some packages, classes, and also configuration files.
Is there any way I can achieve it via "pure" Maven? The only solution I came across till now is to use an antrun plugin and reference an Ant build.xml inside of it.
Thank you,
Mattia
A pure maven solution would be to develop your own maven plugin. Depending on your requirements this can be an overkill, however it is not hard at all, you can see how to achieve this here.
This is a limitation of Maven. One of Maven's purposes is to not have a build script. You should simply use the plugins as available, and setup your project the right way, and magically, everything will build!
There is one solution: Use Ant. Well, not to redo your whole project with Ant, but with the antrun plugin, you can run a few Ant tasks at various phases of your Maven build life cycle.
It's been a long, long time since I've used this, so I am not going to try to write a test pom.xml, but I don't remember it being very difficult to use.
Of course, the correct Maven solution is to divide your project up into "common core" code, and then a separate Oracle and MySql client that uses the "common core". By the way, I hope you're not patching source code. Instead, you're using a properties file to do this for you.
I have a bunch of selenium webdriver tests split in different classes. I run these tests across a number of sites but I don't want to run them all on every site.
In the past I used msBuild and c# and wrote testng tests for software automation and I could add something like #Version1.5 after #Test then when I run my tests if the version in my properties file wasn't 5.1 it would skip that test.
Is something like this possible using maven and junit in Java?
Would JUnit Categories to the trick? Maven Surefire supports them but I am not sure how you would dynamically turn them on or off. You could definitely set up maven profiles to turn them on or off and then pass the appropriate profile as part of the maven command.
I have a Maven project that is a set of a Selenium 2 tests that run using JUnit. In other words the only thing in the whole project is JUnit testcases and they all reside in the normal source directory i.e. src/main/java since they are the main source files in the project.
I want to be able to run these same tests using Maven, but since these tests are not actual unit tests or integration tests within the project (they are not testing themselves, they are testing a web app somewhere else), I don't want them to run during the normal build lifecycle. However I still would like to be able to define the test phases/goals within the POM file.
At this point I sort of understand the way the surefire plugin works, I just don't know how to de-couple the executions from the build. I would like all my new executions to be stand-alone so that I can simply run them by doing something like: mvn run-webtests and have the run-webtests phase be something completely different from the compile and package goals of my project.
So I guess I have two overall questions:
1.) Am I on the right track or is there some better way to think of this problem?
2.) What is it that I need to do next to make this work? Create a custom phase? Create a custom goal?
Sorry for asking such a seemingly basic question, but I wasn't able to find any examples of someone doing anything like this.
I think you're on the right track. It's just that Maven is unfortunately lacking in flexibility in some areas. Usually stuff can be made to fit in, but sometimes it can be a real pain. I think the simplest way to make this work is to use a different naming convention for your selenium tests and make sure those are excluded from your "normal" test runs. Then define a profile where you configure the surefire plugin to include your selenium tests and exclude the others. Then to run the selenium tests, you could just
mvn test -P selenium-tests
The only ways that you can set it up so that you could run mvn run-webtests, are
Define a custom lifecycle where "run-webtests" is a phase in the lifecycle, or
Write a plugin, though executing a plugin always has a ':' in it, so it would be more like mvn myplugin:run-webtests.
Those are both more work and harder to maintain than a simple profile in the pom.
OSGI Testing frameworks - some observations.
I am in the middle of writing a system that makes use of OSGI. However all of the popular testing frameworks (Spring-OSGI, PaxExam) require a lot of artefacts for even the simplest test.
Wishlist / Goals
Ideally i would like a single Test that uses TinyBundle to assemble bundles and gives them to the framework. The framework will then do the heavy lifting of starting the container, deploying, running each test, updating the ui to show results etc.
On the surface it would appear that PAX-EXAM would satisfy this but it has additional requirements, which I have not been able to solve, within Eclipse. My problems are:
Each bundle requires a separate project.
Each project gets a manifest.mf in the $project/meta-inf/.
Ideally i would like to bundle all my manifests and "internal" classes in separate sub packages of the test rather than having them scattered about in their respective projects.
I have found packaging everything into the one project just does not work when the tests
execute even if the bundles provisioned are identical in content. However if i split everything into separate projects stuff just works.
Maven
I wish to avoid maven as this implies that a more complex system that would end up requiring building, deploying into the repo which in the end even when automated just slows things down even more. This would conflict with my use of Infinitest which automagically detects changed classes and just executes the right tests.
Eclipse Project Plugin launch configurations.
This approach requires one to pick the bundles to deploy prior to executing the junit test. This of course only works if one has separate projects with a one to one mapping per bundle. Again this goes against my attempts to consolidate all test dependeny bundles under one project.
How, Can it be done ???
How can i achieve this ?
Is this practically possible ?
Whats the simplest alternative ?
One alternative, which also leverages Pax Exam, is what we did in an OSGi testing framework (that tests OSGi framework implementations). Rather than duplicating the whole explanation of how it works, you can find that here:
http://opensource.luminis.net/wiki/display/OSGITEST/OSGi+testing+framework
It does not use Maven, and writing new tests is explained here:
http://opensource.luminis.net/wiki/display/OSGITEST/Writing+a+framework+test
Maybe some of the solutions can inspire you. All in all, there are many test frameworks out there for OSGi (just like there are for non-OSGi) but so far there has one been any one that "makes the rest obsolete".