Alien Driven Development
Integrationstests with Pleasure
http://blog.eisele.net/
@myfear
http://myfear.com/+
markus@eisele.net
© msg Applied Technology Research, 01.07.2013Markus Eisele - @myfear - http://blog.eisele.net4
Testing is too hard.
Testin...
© msg Applied Technology Research, 01.07.2013Markus Eisele - @myfear - http://blog.eisele.net5
Unit Tests Integration Test...
© msg Applied Technology Research, 01.07.2013Markus Eisele - @myfear - http://blog.eisele.net6
You can’t fix what you can’...
© msg Applied Technology Research, 01.07.2013Markus Eisele - @myfear - http://blog.eisele.net7
You can’t fix what you can’...
© msg Applied Technology Research, 01.07.2013Markus Eisele - @myfear - http://blog.eisele.net8
You can’t fix what you can’...
© msg Applied Technology Research, 01.07.2013Markus Eisele - @myfear - http://blog.eisele.net9
You can’t develop what you ...
© msg Applied Technology Research, 01.07.2013Markus Eisele - @myfear - http://blog.eisele.net10
Not testing needs to be mo...
© msg Applied Technology Research, 01.07.2013Markus Eisele - @myfear - http://blog.eisele.net11
What is touched
by testing...
© msg Applied Technology Research, 01.07.2013Markus Eisele - @myfear - http://blog.eisele.net12
Frameworks
Build
IDE
Serve...
© msg Applied Technology Research, 01.07.2013Markus Eisele - @myfear - http://blog.eisele.net13
http://www.youtube.com/wat...
© msg Applied Technology Research, 01.07.2013Markus Eisele - @myfear - http://blog.eisele.net14
An Innovative Testing Plat...
© msg Applied Technology Research, 01.07.2013Markus Eisele - @myfear - http://blog.eisele.net15
© msg Applied Technology Research, 01.07.2013Markus Eisele - @myfear - http://blog.eisele.net16
Guiding Principles
 Tests...
© msg Applied Technology Research, 01.07.2013Markus Eisele - @myfear - http://blog.eisele.net17
SourceTest
IDE
Build
Frame...
arquillian
© msg Applied Technology Research, 01.07.2013Markus Eisele - @myfear - http://blog.eisele.net18
SourceTest
IDE
...
© msg Applied Technology Research, 01.07.2013Markus Eisele - @myfear - http://blog.eisele.net19
Lifecycle
 Select Contain...
© msg Applied Technology Research, 01.07.2013Markus Eisele - @myfear - http://blog.eisele.net20
Basic Setup
<dependencyMan...
© msg Applied Technology Research, 01.07.2013Markus Eisele - @myfear - http://blog.eisele.net21
<dependencies>
<dependency...
© msg Applied Technology Research, 01.07.2013Markus Eisele - @myfear - http://blog.eisele.net22
Java EE Container Support
...
© msg Applied Technology Research, 01.07.2013Markus Eisele - @myfear - http://blog.eisele.net23
<profiles>
<profile>
<id>a...
© msg Applied Technology Research, 01.07.2013Markus Eisele - @myfear - http://blog.eisele.net24
<?xml version="1.0" encodi...
© msg Applied Technology Research, 01.07.2013Markus Eisele - @myfear - http://blog.eisele.net25
@Stateless
public class He...
© msg Applied Technology Research, 01.07.2013Markus Eisele - @myfear - http://blog.eisele.net26
@RunWith(Arquillian.class)...
© msg Applied Technology Research, 01.07.2013Markus Eisele - @myfear - http://blog.eisele.net27
© msg Applied Technology Research, 01.07.2013Markus Eisele - @myfear - http://blog.eisele.net28
http://www.youtube.com/wat...
© msg Applied Technology Research, 01.07.2013Markus Eisele - @myfear - http://blog.eisele.net29
https://docs.jboss.org/aut...
© msg Applied Technology Research, 01.07.2013Markus Eisele - @myfear - http://blog.eisele.net30
Graphene
https://docs.jbos...
© msg Applied Technology Research, 01.07.2013Markus Eisele - @myfear - http://blog.eisele.net31
Warp
https://github.com/ar...
© msg Applied Technology Research, 01.07.2013Markus Eisele - @myfear - http://blog.eisele.net32
Warp
.initiate(new Activit...
© msg Applied Technology Research, 01.07.2013Markus Eisele - @myfear - http://blog.eisele.net33
Transaction
https://github...
© msg Applied Technology Research, 01.07.2013Markus Eisele - @myfear - http://blog.eisele.net34
Persistence
https://docs.j...
© msg Applied Technology Research, 01.07.2013Markus Eisele - @myfear - http://blog.eisele.net35
https://docs.jboss.org/aut...
© msg Applied Technology Research, 01.07.2013Markus Eisele - @myfear - http://blog.eisele.net36
Performance
https://docs.j...
© msg Applied Technology Research, 01.07.2013Markus Eisele - @myfear - http://blog.eisele.net37
Seam 2
https://docs.jboss....
© msg Applied Technology Research, 01.07.2013Markus Eisele - @myfear - http://blog.eisele.net38
Spring
https://github.com/...
© msg Applied Technology Research, 01.07.2013Markus Eisele - @myfear - http://blog.eisele.net39
Guice
https://github.com/a...
© msg Applied Technology Research, 01.07.2013Markus Eisele - @myfear - http://blog.eisele.net40
Spock
https://github.com/a...
© msg Applied Technology Research, 01.07.2013Markus Eisele - @myfear - http://blog.eisele.net41
Screen Recorder
https://gi...
© msg Applied Technology Research, 01.07.2013Markus Eisele - @myfear - http://blog.eisele.net42
Jacoco
https://github.com/...
© msg Applied Technology Research, 01.07.2013Markus Eisele - @myfear - http://blog.eisele.net43
Google Web Toolkit
https:/...
© msg Applied Technology Research, 01.07.2013Markus Eisele - @myfear - http://blog.eisele.net44
Portal
https://github.com/...
© msg Applied Technology Research, 01.07.2013Markus Eisele - @myfear - http://blog.eisele.net45
https://github.com/arquill...
© msg Applied Technology Research, 01.07.2013Markus Eisele - @myfear - http://blog.eisele.net46
JRebel
https://github.com/...
© msg Applied Technology Research, 01.07.2013Markus Eisele - @myfear - http://blog.eisele.net47
OSGi
https://github.com/ar...
© msg Applied Technology Research, 01.07.2013Markus Eisele - @myfear - http://blog.eisele.net48
@Test
public void testBund...
© msg Applied Technology Research, 01.07.2013Markus Eisele - @myfear - http://blog.eisele.net49
https://github.com/arquill...
© msg Applied Technology Research, 01.07.2013Markus Eisele - @myfear - http://blog.eisele.net50
iOS Platform
https://githu...
© msg Applied Technology Research, 01.07.2013Markus Eisele - @myfear - http://blog.eisele.net51
QUnit automates the QUnit ...
© msg Applied Technology Research, 01.07.2013Markus Eisele - @myfear - http://blog.eisele.net52
Cukespace … deploy and run...
© msg Applied Technology Research, 01.07.2013Markus Eisele - @myfear - http://blog.eisele.net53
© msg Applied Technology Research, 01.07.2013Markus Eisele - @myfear - http://blog.eisele.net54
Questions?
Alien driven-development
Upcoming SlideShare
Loading in …5
×

Alien driven-development

2,036 views

Published on

An Introduction to Java EE Integration testing with Arquillian. This session gives an overview of base functionality and extensions and shows how to use them.

Mad a first appearance at http://www.jayday.de/en/trainer/markus-eisele/

Published in: Technology
0 Comments
3 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
2,036
On SlideShare
0
From Embeds
0
Number of Embeds
6
Actions
Shares
0
Downloads
0
Comments
0
Likes
3
Embeds 0
No embeds

No notes for slide

Alien driven-development

  1. 1. Alien Driven Development Integrationstests with Pleasure
  2. 2. http://blog.eisele.net/ @myfear http://myfear.com/+ markus@eisele.net
  3. 3. © msg Applied Technology Research, 01.07.2013Markus Eisele - @myfear - http://blog.eisele.net4 Testing is too hard. Testing isn’t fun. Testing is so sloow. Testing sucks!
  4. 4. © msg Applied Technology Research, 01.07.2013Markus Eisele - @myfear - http://blog.eisele.net5 Unit Tests Integration Tests System Tests Complexity Functional Test Code
  5. 5. © msg Applied Technology Research, 01.07.2013Markus Eisele - @myfear - http://blog.eisele.net6 You can’t fix what you can’t run.
  6. 6. © msg Applied Technology Research, 01.07.2013Markus Eisele - @myfear - http://blog.eisele.net7 You can’t fix what you can’t debug.
  7. 7. © msg Applied Technology Research, 01.07.2013Markus Eisele - @myfear - http://blog.eisele.net8 You can’t fix what you can’t test.
  8. 8. © msg Applied Technology Research, 01.07.2013Markus Eisele - @myfear - http://blog.eisele.net9 You can’t develop what you can’t test.
  9. 9. © msg Applied Technology Research, 01.07.2013Markus Eisele - @myfear - http://blog.eisele.net10 Not testing needs to be more painful And time consuming than using testing.
  10. 10. © msg Applied Technology Research, 01.07.2013Markus Eisele - @myfear - http://blog.eisele.net11 What is touched by testing? Frameworks Build IDE Server Client Code
  11. 11. © msg Applied Technology Research, 01.07.2013Markus Eisele - @myfear - http://blog.eisele.net12 Frameworks Build IDE Server Client EE Spring DI Maven Ant Gradle Eclipse NetBeans IntelliJ GlassFish Tomcat AS7 IE Chrome FF … … … … … Code Source Test Other …
  12. 12. © msg Applied Technology Research, 01.07.2013Markus Eisele - @myfear - http://blog.eisele.net13 http://www.youtube.com/watch?v=VpZmIiIXuZ0
  13. 13. © msg Applied Technology Research, 01.07.2013Markus Eisele - @myfear - http://blog.eisele.net14 An Innovative Testing Platform for the JVM
  14. 14. © msg Applied Technology Research, 01.07.2013Markus Eisele - @myfear - http://blog.eisele.net15
  15. 15. © msg Applied Technology Research, 01.07.2013Markus Eisele - @myfear - http://blog.eisele.net16 Guiding Principles  Tests should be portable to any supported container  Tests should be executable from IDE and build tool  Should extend or integrate existing test frameworks https://docs.jboss.org/author/display/ARQ/Reference+Guide
  16. 16. © msg Applied Technology Research, 01.07.2013Markus Eisele - @myfear - http://blog.eisele.net17 SourceTest IDE Build Frameworks Tests Classes Server Deps Package ~ Client
  17. 17. arquillian © msg Applied Technology Research, 01.07.2013Markus Eisele - @myfear - http://blog.eisele.net18 SourceTest IDE Build Tests Classes Server Deps Package ClientPackage Client
  18. 18. © msg Applied Technology Research, 01.07.2013Markus Eisele - @myfear - http://blog.eisele.net19 Lifecycle  Select Container  Start Container  Package Archive  Run Test in Container  Show Results  Undeploy / Disconnect
  19. 19. © msg Applied Technology Research, 01.07.2013Markus Eisele - @myfear - http://blog.eisele.net20 Basic Setup <dependencyManagement> <dependencies> <dependency> <groupId>org.jboss.arquillian</groupId> <artifactId>arquillian-bom</artifactId> <version>1.0.4.Final</version> <scope>import</scope> <type>pom</type> </dependency> </dependencies> </dependencyManagement>
  20. 20. © msg Applied Technology Research, 01.07.2013Markus Eisele - @myfear - http://blog.eisele.net21 <dependencies> <dependency> <groupId>javax</groupId> <artifactId>javaee-web-api</artifactId> <version>7.0</version> <scope>provided</scope> </dependency> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>4.8.1</version> <scope>test</scope> </dependency> <dependency> <groupId>org.jboss.arquillian.junit</groupId> <artifactId>arquillian-junit-container</artifactId> <scope>test</scope> </dependency> <!-- … --> </dependencies>
  21. 21. © msg Applied Technology Research, 01.07.2013Markus Eisele - @myfear - http://blog.eisele.net22 Java EE Container Support Embedded Managed Remote https://docs.jboss.org/author/display/ARQ/Container+adapters
  22. 22. © msg Applied Technology Research, 01.07.2013Markus Eisele - @myfear - http://blog.eisele.net23 <profiles> <profile> <id>arquillian-glassfish-managed</id> <dependencies> <dependency> <groupId>org.jboss.arquillian.container</groupId> <artifactId>arquillian-glassfish-managed-3.1</artifactId> <version>1.0.0.CR4</version> <scope>test</scope> </dependency> </dependencies> </profile> </profiles> https://docs.jboss.org/author/display/ARQ/Container+adapters
  23. 23. © msg Applied Technology Research, 01.07.2013Markus Eisele - @myfear - http://blog.eisele.net24 <?xml version="1.0" encoding="UTF-8"?> <arquillian xmlns="http://jboss.org/schema/arquillian" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation=" http://jboss.org/schema/arquillian http://jboss.org/schema/arquillian/arquillian_1_0.xsd"> <container qualifier="glassfish" default="true"> <configuration> <property name="glassFishHome">D:glassfish4-b85</property> <property name="adminHost">localhost</property> <property name="adminPort">4848</property> </configuration> </container> </arquillian>
  24. 24. © msg Applied Technology Research, 01.07.2013Markus Eisele - @myfear - http://blog.eisele.net25 @Stateless public class HelloBean { public String sayHello(String name) { return "Hello " + name + "!"; } }
  25. 25. © msg Applied Technology Research, 01.07.2013Markus Eisele - @myfear - http://blog.eisele.net26 @RunWith(Arquillian.class) public class HelloBeanIntegrationTest { @EJB HelloBean hello; @Deployment public static WebArchive createDeployment() { return ShrinkWrap.create(WebArchive.class) .addClass(HelloBean.class) .addAsWebInfResource(EmptyAsset.INSTANCE, "beans.xml"); } @Test public void shouldSayHello() throws Exception { Assert.assertEquals("Hello Earthling!", hello.sayHello("Earthling")); } }
  26. 26. © msg Applied Technology Research, 01.07.2013Markus Eisele - @myfear - http://blog.eisele.net27
  27. 27. © msg Applied Technology Research, 01.07.2013Markus Eisele - @myfear - http://blog.eisele.net28 http://www.youtube.com/watch?v=VpZmIiIXuZ0
  28. 28. © msg Applied Technology Research, 01.07.2013Markus Eisele - @myfear - http://blog.eisele.net29 https://docs.jboss.org/author/display/ARQ/Drone Drone …brings power of Selenium into Arquillian framework. @Drone WebDriver driver; @Test @InSequence(1) public void login() { driver.get(contextPath + "home.jsf"); driver.findElement(USERNAME_FIELD).sendKeys(USERNAME); driver.findElement(PASSWORD_FIELD).sendKeys(PASSWORD); driver.findElement(LOGIN_BUTTON).click(); Assert.isTrue("User is logged in.", driver.findElement(LOGGED_IN).isDisplayed()); }
  29. 29. © msg Applied Technology Research, 01.07.2013Markus Eisele - @myfear - http://blog.eisele.net30 Graphene https://docs.jboss.org/author/display/ARQ/Graphene …brings power of Selenium and AJAX into Arquillian framework. @RunWith(Arquillian.class) public class TestLogin { @Drone WebDriver browser; @Page HomePage homePage; @Test(expects = LoginFailedException.class) public void testLoginFailed(){ homePage.login("non-existent", "user"); }
  30. 30. © msg Applied Technology Research, 01.07.2013Markus Eisele - @myfear - http://blog.eisele.net31 Warp https://github.com/arquillian/arquillian-extension-warp/blob/master/README.md …client-side test which asserts server-side logic. @RunWith(Arquillian.class) @WarpTest @RunAsClient public class BasicTest { //... } Warp .initiate(Activity) .inspect(Inspection); @BeforeServlet @AfterServlet @BeforePhase @AfterPhase
  31. 31. © msg Applied Technology Research, 01.07.2013Markus Eisele - @myfear - http://blog.eisele.net32 Warp .initiate(new Activity() { public void perform() { WebElement nameInput = browser.findElement(By.id("helloWorldJsf:nameInput")); nameInput.sendKeys("X"); browser.findElement(By.tagName("body")).click(); }}) .inspect(new Inspection() { private static final long serialVersionUID = 1L; @Inject CdiBean myBean; private String updatedName; @BeforePhase(UPDATE_MODEL_VALUES) public void initial_state_havent_changed_yet() { assertEquals("John", myBean.getName()); } });
  32. 32. © msg Applied Technology Research, 01.07.2013Markus Eisele - @myfear - http://blog.eisele.net33 Transaction https://github.com/arquillian/arquillian-extension-transaction …enhances your tests with transaction support. @RunWith(Arquillian.class) public class TransactionTest { @Deployment public static WebArchive deployment() { //... } @Test @Transactional(TransactionMode.ROLLBACK) public void test() { //…. } }
  33. 33. © msg Applied Technology Research, 01.07.2013Markus Eisele - @myfear - http://blog.eisele.net34 Persistence https://docs.jboss.org/author/display/ARQ/Persistence …helps with database wrangling. @RunWith(Arquillian.class) public class PersistenceTest { @Deployment public static WebArchive deployment() { //... .addAsResource("test-persistence.xml", "persistence.xml"); } @Test @UsingDataSet("datasets/users.yml") @ShouldMatchDataSet("datasets/expected-users.yml") public void test() { //…. } }
  34. 34. © msg Applied Technology Research, 01.07.2013Markus Eisele - @myfear - http://blog.eisele.net35 https://docs.jboss.org/author/display/ARQ/Persistence @RunWith(Arquillian.class) @CreateSchema("scripts/ddl.sql") public class PersistenceTest { @Deployment public static WebArchive deployment() { //... .addAsManifestResource("test-persistence.xml", "persistence.xml"); } @Test @UsingDataSet("datasets/users.yml") @ShouldMatchDataSet("datasets/expected-users.yml") @CleanupUsingScript("drop-schema.sql") public void test() { //…. } }
  35. 35. © msg Applied Technology Research, 01.07.2013Markus Eisele - @myfear - http://blog.eisele.net36 Performance https://docs.jboss.org/author/display/ARQ/Performance …keeps your tests in time. @RunWith(Arquillian.class) @PerformanceTest(resultsThreshold = 2) public class PersformanceTest { @Deployment public static WebArchive deployment() { //... } @Test @Performance(time = 575) public void test() { //…. } }
  36. 36. © msg Applied Technology Research, 01.07.2013Markus Eisele - @myfear - http://blog.eisele.net37 Seam 2 https://docs.jboss.org/author/display/ARQ/Seam+2 …bringing Seam 2 Context to Arquillian. @RunWith(Arquillian.class) public class ComponentInjectionTest { @Deployment public static WebArchive deployment() { //... .addAsResource(EmptyAsset.INSTANCE, "seam.properties"); } @In SomeSeamComponent component; @Test public void test() { assertThat(component).isNotNull(); } }
  37. 37. © msg Applied Technology Research, 01.07.2013Markus Eisele - @myfear - http://blog.eisele.net38 Spring https://github.com/arquillian/arquillian-extension-spring …bringing Spring 2 and 3 to Arquillian. • Injection of Spring beans into test classes • Configuration from both XML and Java-based config • Injecting beans configured in web application (e.g. DispatcherServlet) for tests annotated with @SpringWebConfiguration • Support for both Spring(@Autowired, @Qualifier, @Required) and JSR-330(@Inject, @Named) annotations • Bean initialization support (@PostConstruct) • Auto packaging the spring-context and spring-web artifacts.
  38. 38. © msg Applied Technology Research, 01.07.2013Markus Eisele - @myfear - http://blog.eisele.net39 Guice https://github.com/arquillian/arquillian-extension-guice …bringing Guice DI to Arquillian. @RunWith(Arquillian.class) @GuiceConfiguration(AppointmentModule.class) public class ComponentInjectionTest { @Deployment public static WebArchive deployment() { //... } @Inject @Named("appointmentService") private AppointmentService appointmentService; @Test public void test() { assertThat(appointmentService).isNotNull(); } }
  39. 39. © msg Applied Technology Research, 01.07.2013Markus Eisele - @myfear - http://blog.eisele.net40 Spock https://github.com/arquillian/arquillian-testrunner-spock …bringing Spock Testing to Arquillian. @Inject AccountService service def "transferring between accounts should result in account withdrawal and deposit"() { when: service.transfer(from, to, amount) then: from.balance == fromBalance to.balance == toBalance where: from << [new Account(100), new Account(10)] to << [new Account(50), new Account(90)] amount << [50, 10] fromBalance << [50, 0] toBalance << [100, 100] }
  40. 40. © msg Applied Technology Research, 01.07.2013Markus Eisele - @myfear - http://blog.eisele.net41 Screen Recorder https://github.com/arquillian/arquillian-extension-screenrecorder …records your tests. <dependency> <groupId>org.jboss.arquillian.extension</groupId> <artifactId>arquillian-screen-recorder</artifactId> <version>1.0.0.Alpha1</version> </dependency> <extension qualifier="screenRecorder"> <property name="rootFolder">target</property> <property name="videoFolder">video</property> <property name="videoName">myTestVideo</property> <property name="video">suite</property> <property name="screenshot">test</property> </extension>
  41. 41. © msg Applied Technology Research, 01.07.2013Markus Eisele - @myfear - http://blog.eisele.net42 Jacoco https://github.com/arquillian/arquillian-extension-jacoco …gives you test-coverage. <plugin> <groupId>org.jacoco</groupId> <artifactId>jacoco-maven-plugin</artifactId> <version>0.6.3.201306030806</version> </plugin> <dependency> <groupId>org.jboss.arquillian.extension</groupId> <artifactId>arquillian-jacoco</artifactId> <version>1.0.0.Alpha5</version> </dependency>
  42. 42. © msg Applied Technology Research, 01.07.2013Markus Eisele - @myfear - http://blog.eisele.net43 Google Web Toolkit https://github.com/arquillian/arquillian-extension-gwt … brings Arquillian to GWT. @Test @RunAsGwtClient(moduleName = "org.myapp.MyGwtModule") public void testGreetingService() { GreetingServiceAsync greetingService = GWT.create(GreetingService.class); greetingService.greetServer("Hello!", new AsyncCallback<String>() { @Override public void onFailure(Throwable caught) { Assert.fail("Request failure: " + caught.getMessage()); } @Override public void onSuccess(String result) { assertEquals("Received invalid response from Server", "Welcome!", result); finishTest(); } }); delayTestFinish(5000); }
  43. 43. © msg Applied Technology Research, 01.07.2013Markus Eisele - @myfear - http://blog.eisele.net44 Portal https://github.com/arquillian/arquillian-extension-portal …help you write tests for portlets. @RunWith(Arquillian.class) @PortalTest public class PortletTest { @Deployment public static WebArchive deployment() { //... } @ArquillianResource @PortalURL URL portalURL; @Test @RunAsClient public void renderFacesPortlet() throws Exception { browser.get(portalURL.toString()); }
  44. 44. © msg Applied Technology Research, 01.07.2013Markus Eisele - @myfear - http://blog.eisele.net45 https://github.com/arquillian/arquillian-extension-byteman Byteman …gives you runtime bytecode manipulation. @RunWith(Arquillian.class) @BMRules( @BMRule( name = "Throw exception on success", targetClass = "StatelessManagerBean", targetMethod = "forcedClassLevelFailure", action = "throw new java.lang.RuntimeException()") ) public class BytemanFaultInjectionTestCase { //… @EJB(mappedName = "java:module/StatelessManagerBean") private StatelessManager bean; @Test(expected = EJBException.class) { Assert.assertNotNull("Verify bean was injected", bean); bean.forcedMethodLevelFailure(); }
  45. 45. © msg Applied Technology Research, 01.07.2013Markus Eisele - @myfear - http://blog.eisele.net46 JRebel https://github.com/arquillian/arquillian-extension-jrebel … hot-deploy your integration tests. <dependency> <groupId>org.jboss.arquillian.extension</groupId> <artifactId>arquillian-jrebel-impl</artifactId> <version>1.0.0.Alpha1</version> </dependency>
  46. 46. © msg Applied Technology Research, 01.07.2013Markus Eisele - @myfear - http://blog.eisele.net47 OSGi https://github.com/arquillian/arquillian-container-osgi … brings Arquillian to OSGi Frameworks. @RunWith(Arquillian.class) public class SimpleBundleTestCase { @ArquillianResource BundleContext context; @Deployment public static JavaArchive createdeployment() { final JavaArchive archive = ShrinkWrap.create(JavaArchive.class, "test.jar"); archive.setManifest(new Asset() { public InputStream openStream() { OSGiManifestBuilder builder = OSGiManifestBuilder.newInstance(); builder.addBundleSymbolicName(archive.getName()); builder.addBundleManifestVersion(2); builder.addImportPackages(Bundle.class); return builder.openStream(); } }); return archive; }
  47. 47. © msg Applied Technology Research, 01.07.2013Markus Eisele - @myfear - http://blog.eisele.net48 @Test public void testBundleContextInjection() { assertNotNull("BundleContext injected", context); assertEquals("System Bundle ID", 0, context.getBundle().getBundleId()); } @Test public void testBundleInjection(@ArquillianResource Bundle bundle) { // Assert that the bundle is injected assertNotNull("Bundle injected", bundle); // Assert that the bundle is in state RESOLVED // Note when the test bundle contains the test case it // must be resolved already when this test method is called assertEquals("Bundle RESOLVED", Bundle.RESOLVED, bundle.getState()); // Start the bundle bundle.start(); assertEquals("Bundle ACTIVE", Bundle.ACTIVE, bundle.getState()); https://github.com/arquillian/arquillian-container-osgi
  48. 48. © msg Applied Technology Research, 01.07.2013Markus Eisele - @myfear - http://blog.eisele.net49 https://github.com/arquillian/arquillian-droidium …brings Native and WebDriver based testing to Android devices. <container qualifier="android"> <configuration> <property name="adapterImplClass"> org.jboss.arquillian.container.android.managed.AndroidManagedDeployableContainer </property> </configuration> </container> @ArquillianResource AndroidDevice android; @Test @OperateOnDeployment("android1") public void test01() { assertTrue(android != null); } Droidium
  49. 49. © msg Applied Technology Research, 01.07.2013Markus Eisele - @myfear - http://blog.eisele.net50 iOS Platform https://github.com/arquillian/arquillian-extension-ios …brings Native and WebDriver based testing to iOS devices.
  50. 50. © msg Applied Technology Research, 01.07.2013Markus Eisele - @myfear - http://blog.eisele.net51 QUnit automates the QUnit JavaScript testing on Web Applications @RunWith(QUnitRunner.class) @QUnitResources("src/test/resources/assets") public class QUnitRunnerTestCase { @QUnitTest("tests/ticketmonster/qunit-tests-dom.html") @InSequence(1) public void qunitDomTest() { // empty body - only the annotations are used }
  51. 51. © msg Applied Technology Research, 01.07.2013Markus Eisele - @myfear - http://blog.eisele.net52 Cukespace … deploy and run Cucumber features using Arquillian. @RunWith(ArquillianCucumber.class) public class CukesInBellyTest { @Deployment public static Archive<?> createDeployment() { return ShrinkWrap.create(WebArchive.class) //… .addAsResource("my/features/cukes.feature"); } @EJB private CukeService service; @Inject private CukeLocator cukeLocator; @When("^I persist my cuke$") public void persistCuke() { this.service.persist(this.cukeLocator.findCuke()); } } https://github.com/cukespace/cukespace
  52. 52. © msg Applied Technology Research, 01.07.2013Markus Eisele - @myfear - http://blog.eisele.net53
  53. 53. © msg Applied Technology Research, 01.07.2013Markus Eisele - @myfear - http://blog.eisele.net54 Questions?

×