We wish to introduce Selenium testing to our maven build process. Happily, there is a ton of information available on how to do this, but I'm having trouble figuring out how to handle one of our requirements.
In an effort to separate our testing layers, we want to use mock service objects for the ui tests. All of these objects are already defined in Spring configuration files that we use in unit tests. Wiring these services is easy in a unit test (we're using #ContextConfiguration), but I don't know how to handle this configuration swap when we're deploying the war to Jetty for Selenium tests.
We're using:
Spring MVC 3.0
Maven
Hudson
Worst: introduce special user/interface parameter/checkbox/role. In an application remember to use mocks for this special case everywhere in the code. Horrible in maintenance, error-prone and, let's face it, pretty lame. Most common thou...
Easiest solution: develop conditional includes in your Spring application context:
<import resource="services-${env}.xml"/>
where ${env} comes from pom.xml:
<properties>
<env>prd</env> <!-- or test depending on build profile -->
</properties>
Remember to turn on resources filtering and use build profiles.
when doing Selenium tests. Switching can be done during Maven build or by some other filtering tool. Both files (services-prd.xml and services-test.xml) define same beans (same interfaces and/or ids), but of course the latter one uses mock implementations.
Best (IMHO): if you need to change the implementation at runtime, AOP + JMX will be great. Just wrap your real services with aspects and depending on some flag (accessible via JMX), use real services or mocks. Very clean and noninvasive.
Related
I have a quite big set of Selenium driven UI tests, that are very cumbersome to maintain. I've read about Arquillian Graphene and its benefits, making life with Selenium less painfull.
I wonder if it's possible to use Arquillian Graphene (2) without using the Arquillian framework underneath it, i.e. simply drive Selenium tests against a running application.
Do you have any experiences or are there any showstoppers from making this setup work?
Cheers, Chris
Yes, using the 'standalone' version will remove the Container/Deployment support.
The only problem is you'll also miss all the Container/Deployment metadata that Arquillian automatically fetch and use to e.g. construct the URL injection.
As of Graphene 2.1.0.Alpha2 there was added support to configure a URL in arquillian.xml if one was not provided automatically. Using that feature should allow you to use Graphene against an already deployed application as if it was deployed by Arquillian.
Essentially put this in your arquillian.xml file:
<arquillian>
<extension name="graphene">
<property name="url">http://localhost:8080/app/</property>
</extension>
</arquillian>
See https://issues.jboss.org/browse/ARQGRA-374 for more details.
Ok, I found the answer myself: yes, it is possible. But I'll have to reword the question a little bit: Is it possible to use Arquillian Graphene without using Arquillian container management.
What I do now is have a already deployed application inside its container, i.e. I do not use Arquillian to deploy all or part of the application, and I use Graphene 2 and Drone to drive my Selenium tests on that application.
The only documentation I found regarding this setup is https://docs.jboss.org/author/display/ARQGRA2/Framework+Integration+Options
Arquillian Mode Options
You can choose between following Arquillian modes
Standalone
runs tests without container integration, only lifecycle of extensions is managed
allows to use Graphene independently of Arquillian containers and deployment management
Yes, I have been using it for the past 18 months in a standalone mode.
Please check here for more info.
http://www.testautomationguru.com/selenium-webdriver-automation-using-arquillian-framework/
Could anyone provide a complete flow test example (channels, gateways, etc) using jUnit4 or other Test tool for spring integration? I am working without XML, thus I prefer a Java-config test initiation.
It depends on your application; for pure annotation configuration start with this framework test class, it has lots of tests.
If you're using the Java DSL, start here.
I am currently investigating how best to test our OSGi application intended to run on Apache Karaf. The obvious option is Pax Exam with labs-paxexam-karaf (see http://iocanel.blogspot.com/2012/01/advanced-integration-testing-with-pax.html for a tutorial). However, I am concerned about performance (since Pax Exam apparently starts a new framework for every test method). I've also found that Arquillian has some OSGi support, though that isn't its main focus. JUnit4osgi isn't an option, as it only supports JUnit 3.
For someone unfamiliar with either framework, which is better to start with? What are the tradeoffs?
Why use Arquillian if you're after proper OSGi support? =)
When looking at PaxExam make sure the docs refer to PaxExam 2 - there are substantial differences between v 1 and 2.
PaxExam will take a while to get to grips with, but you'll learn heaps about OSGi in the process (definitely a good thing, but can still hurt).
In parallel to #Dmytro's answer, the Test Containers include a Native container which is run with the same VM as the junit test - meaning you can launch with debug in Eclipse. This works especially well with the org.eclipse.m2e:lifecycle-mapping maven eclipse plugin and the org.ops4j.pax.exam:maven-paxexam-plugin. This method is fantastic, complete IDE integration.
PaxExam documentation is a bit sparse, but there are some good examples (see the Native launcher with main method that provides interactive shell) and wiki doc. If you get stuck the mailing list people (general#lists.ops4j.org) are very helpful.
Another alternative is to look at Karaf's paxexam, very slick and easy to get a Karaf instance up and running (features.xml etc).
Personally, I just use PaxExam2 as I'd prefer to have no explicit dependencies on the framework provider (nothing against Karaf at all, it rocks).
Based on Reactor Strategies Pax-Exam can run all test methods in the same OSGi container.
The EagerSingleStagedReactorFactory of Pax Exam 2.x (aliased to PerClass in Pax 3.0) lets you run all test methods of a given class in the same OSGi container.
With the PerSuite strategy introduced in Pax Exam 3.0.0.M1, all test classes of your suite run in the same container.
By the way, Pax Exam 3.0 supports Java EE and CDI containers in addition to OSGi, so there is even more functional similarity with Arquillian, only Pax Exam is coming from the opposite end.
With Pax Exam, there is no need to assemble deployments in ShrinkWrap style, they are built automatically from the classpath. Moreover, you can run suites of test classes with a shared configuration.
I am looking for mocking framework to use in my osgi/eclipse test fragments. I have looked at:
http://www.jmock.org/download.html
but since its not osgi I need to convert it manually. I have tried to google for some mocking frameworks that works with osgi out of the box but have not been able to find any, does osgi developers not use mocking?
One solution will be to create mock objects of OSGi objects (like BundleContext and ServiceReference). You can use any mocking framework for this and of course you don't have to run the test in an OSGi container. This will be OK for simple scenarios.
If you want to test inside a container, you have the following options:
Pax-Exam
Spring DM Testing facilities
Actually Mockito works quite good with OSGI applications, since it has OSGI manifest. You can simply add it to your target platform from the latest orbit repository. I managed to make Powermock also working for Eclipse Plugins and it is available as well as update site at https://code.google.com/p/powermock-osgi/
I was wondering whether it is possible to use Maven2 to automatically configure a Glassfish 2.1 with JNDI Resources, Datasources and Mail-Sessions for my integration tests.
Also I wonder whether it is possible to create some sort of benchmarks that might then be tracked using continuum or Hudson.
I was wondering whether it is possible to use Maven2 to automatically configure a Glassfish 2.1 with JNDI Resources, Datasources and Mail-Sessions for my integration tests.
I'm not sure Cargo does provide anything to configure Mail-Sessions. And anyway, from what I can see in DataSource+and+Resource+Support, there is no support at all for GlassFish. I'd simply configure the installed container against which you run your integration tests.
Also I wonder whether it is possible to create some sort of benchmarks that might then be tracked using continuum or Hudson.
You could run JMeter performance tests. Hudson has a Performance Plugin allowing to generate a trend graphic report from the results. Also maybe have a look at JChav (seems dormant though).