the future of enterprise testing - jfokus€¦ · the future of enterprise testing aslak knutsen...

26
The future of enterprise testing The future of enterprise testing Aslak Knutsen Aslak Knutsen JBoss, by Red Hat JBoss, by Red Hat aslakknutsen aslakknutsen Dan Allen Dan Allen JBoss, by Red Hat JBoss, by Red Hat mojavelinux mojavelinux

Upload: others

Post on 25-Jun-2020

13 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: The future of enterprise testing - Jfokus€¦ · The future of enterprise testing Aslak Knutsen JBoss, by Red Hat aslakknutsen ... Reducing enterprise testing to child's play Unit

The future of enterprise testingThe future of enterprise testing

Aslak KnutsenAslak KnutsenJBoss, by Red HatJBoss, by Red Hat aslakknutsenaslakknutsen

Dan AllenDan AllenJBoss, by Red HatJBoss, by Red Hat mojavelinuxmojavelinux

Page 2: The future of enterprise testing - Jfokus€¦ · The future of enterprise testing Aslak Knutsen JBoss, by Red Hat aslakknutsen ... Reducing enterprise testing to child's play Unit

2

Agenda

● Why Java EE is harder than it should be● How component models apply to testing● Tools that help you develop & test with confidence

● ShrinkWrap - Skip the build● Arquillian - Test in-container

● Demo, demo, demo● What's coming next, with demos

#arquillian

Page 3: The future of enterprise testing - Jfokus€¦ · The future of enterprise testing Aslak Knutsen JBoss, by Red Hat aslakknutsen ... Reducing enterprise testing to child's play Unit

3

No tests #fail

Page 4: The future of enterprise testing - Jfokus€¦ · The future of enterprise testing Aslak Knutsen JBoss, by Red Hat aslakknutsen ... Reducing enterprise testing to child's play Unit

4

Unit tests vs integration tests

Unit● Attributes

● Fine-grained● Simple● Single API call

● Perception● Fast, fast, fast● Easily run in an IDE

Integration● Attributes

● Coarse-grained● Complex● Component interactions

● Perception● Sloooooooow● Run in an IDE? How?

Page 5: The future of enterprise testing - Jfokus€¦ · The future of enterprise testing Aslak Knutsen JBoss, by Red Hat aslakknutsen ... Reducing enterprise testing to child's play Unit

5

The testing “bandgap”

Unit Tests Integration Tests System Tests

Functionality

Setup & configuration

Com

plex

ity (

Men

tal E

ffort)

Page 6: The future of enterprise testing - Jfokus€¦ · The future of enterprise testing Aslak Knutsen JBoss, by Red Hat aslakknutsen ... Reducing enterprise testing to child's play Unit

6

What if integration testing could be...?

● as easy as writing a unit test● run in the IDE (incremental builds, debugging, etc)● ramped up in phases● portable

Page 7: The future of enterprise testing - Jfokus€¦ · The future of enterprise testing Aslak Knutsen JBoss, by Red Hat aslakknutsen ... Reducing enterprise testing to child's play Unit

7

Component models make life easier

● Component● Follows standard programming model● Encapsulates business logic● Packaged in deployable archive

● Container● Host process for deployed applications● Provides services and a runtime for components● Gives you powerful mechanisms for free

Page 8: The future of enterprise testing - Jfokus€¦ · The future of enterprise testing Aslak Knutsen JBoss, by Red Hat aslakknutsen ... Reducing enterprise testing to child's play Unit

8

What's been from Java EE?missing

^

Page 9: The future of enterprise testing - Jfokus€¦ · The future of enterprise testing Aslak Knutsen JBoss, by Red Hat aslakknutsen ... Reducing enterprise testing to child's play Unit

9

A component model for your tests

Page 10: The future of enterprise testing - Jfokus€¦ · The future of enterprise testing Aslak Knutsen JBoss, by Red Hat aslakknutsen ... Reducing enterprise testing to child's play Unit

10

Reducing enterprise testing to child's play

Unit Tests Integration Tests System Tests

Functionality

Setup & configuration

Arquillian's test continuum

Com

plex

ity (

Men

tal E

ffort)

Page 11: The future of enterprise testing - Jfokus€¦ · The future of enterprise testing Aslak Knutsen JBoss, by Red Hat aslakknutsen ... Reducing enterprise testing to child's play Unit

11

How do we get there?

Page 12: The future of enterprise testing - Jfokus€¦ · The future of enterprise testing Aslak Knutsen JBoss, by Red Hat aslakknutsen ... Reducing enterprise testing to child's play Unit

12

Test in-container!Test in-container!Skip the build!

Page 13: The future of enterprise testing - Jfokus€¦ · The future of enterprise testing Aslak Knutsen JBoss, by Red Hat aslakknutsen ... Reducing enterprise testing to child's play Unit

13

n. a fluent API for creating archives such as JARs, WARs andEARs in Java

Project lead: Andrew Lee Rubinger

http://jboss.org/shrinkwrap

Page 14: The future of enterprise testing - Jfokus€¦ · The future of enterprise testing Aslak Knutsen JBoss, by Red Hat aslakknutsen ... Reducing enterprise testing to child's play Unit

14

Benefits of ShrinkWrap

● Incremental IDE compilation● Save and re-run● Skip the build!

● Simple, fluent API● Container deployment adapters● Micro deployments● Export and debugging

Page 15: The future of enterprise testing - Jfokus€¦ · The future of enterprise testing Aslak Knutsen JBoss, by Red Hat aslakknutsen ... Reducing enterprise testing to child's play Unit

15

Fluent archive creationJavaArchive archive = ShrinkWrap.create(JavaArchive.class, "slsb.jar") .addClasses(Greeter.class, GreeterBean.class);System.out.println(archive.toString(true));

slsb.jar:/com//com/acme//com/acme/app//com/acme/app/ejb3//com/acme/app/ejb3/Greeter.class/com/acme/app/ejb3/GreeterBean.class

Yields output:

Page 16: The future of enterprise testing - Jfokus€¦ · The future of enterprise testing Aslak Knutsen JBoss, by Red Hat aslakknutsen ... Reducing enterprise testing to child's play Unit

16

n. a container-oriented testing framework that enablesdevelopers to create portable integration tests for enterpriseapplications; manages the lifecycle of a container and enriches,deploys and runs tests in the container or as a client

Project lead: Aslak Knutsen

http://jboss.org/arquillian

Page 17: The future of enterprise testing - Jfokus€¦ · The future of enterprise testing Aslak Knutsen JBoss, by Red Hat aslakknutsen ... Reducing enterprise testing to child's play Unit

17

An in-container approach to integration testing

1. Start or connect to a container2. Package and deploy test case to container3. Run test in-container4. Capture and report results5. Undeploy test archive

Bring your test to the runtime...

...instead of managing the runtime from your test.

Page 18: The future of enterprise testing - Jfokus€¦ · The future of enterprise testing Aslak Knutsen JBoss, by Red Hat aslakknutsen ... Reducing enterprise testing to child's play Unit

18

Make integration testing a breeze!

Arquillian project mission

Page 19: The future of enterprise testing - Jfokus€¦ · The future of enterprise testing Aslak Knutsen JBoss, by Red Hat aslakknutsen ... Reducing enterprise testing to child's play Unit

19

Prove it.@RunWith(Arquillian.class)public class GreeterTestCase {

@Deployment public static Archive<?> createDeployment() { return ShrinkWrap.create(JavaArchive.class) .addClasses(Greeter.class, GreeterBean.class); } @EJB Greeter greeter; @Test public void shouldBeAbleToInvokeEJB() { Assert.assertEquals("Hello, Earthlings", greeter.greet("Earthlings")); }}

Page 20: The future of enterprise testing - Jfokus€¦ · The future of enterprise testing Aslak Knutsen JBoss, by Red Hat aslakknutsen ... Reducing enterprise testing to child's play Unit

20

What's on the way?What's on the way?

Page 21: The future of enterprise testing - Jfokus€¦ · The future of enterprise testing Aslak Knutsen JBoss, by Red Hat aslakknutsen ... Reducing enterprise testing to child's play Unit

21

● Full-on, container invasion● Multi-deployment, multi-container, multi-node per test● Sophisticated configuration

● ShrinkWrap descriptors● Fluent API for creating/modifying XML descriptors

● Container metadata● Configuration (e.g., ports, urls)● Deployment information (e.g., context path)

● Dependency management● Isolated container dependencies● Adding libraries to test archive

Page 22: The future of enterprise testing - Jfokus€¦ · The future of enterprise testing Aslak Knutsen JBoss, by Red Hat aslakknutsen ... Reducing enterprise testing to child's play Unit

22

Power tools: test framework integration

● Test frameworks are services too!● Extends test component model● Examples:

● JSFUnit*● Cobertura*● Spock*● Selenium*● HTTPUnit● DBUnit

* available

Page 23: The future of enterprise testing - Jfokus€¦ · The future of enterprise testing Aslak Knutsen JBoss, by Red Hat aslakknutsen ... Reducing enterprise testing to child's play Unit

23

Page 24: The future of enterprise testing - Jfokus€¦ · The future of enterprise testing Aslak Knutsen JBoss, by Red Hat aslakknutsen ... Reducing enterprise testing to child's play Unit

24

Benefits of Arquillian

● Write less (boilerplate) test code● As much or as little “integration” as you need● Looks like a unit test, but you're in a true environment!● Run same test in multiple containers● It's a learning environment

Page 25: The future of enterprise testing - Jfokus€¦ · The future of enterprise testing Aslak Knutsen JBoss, by Red Hat aslakknutsen ... Reducing enterprise testing to child's play Unit

25

Arquillian...

● is a container-oriented testing framework● provides a component model for tests● handles test infrastructure & plumbing● ships with a set of container implementations● saves your fail ;)

Page 26: The future of enterprise testing - Jfokus€¦ · The future of enterprise testing Aslak Knutsen JBoss, by Red Hat aslakknutsen ... Reducing enterprise testing to child's play Unit

26

Get involved!

● Download us!● ShrinkWrap - http://jboss.org/shrinkwap● Arquillian - http://jboss.org/arquillian

● Participate with us!● Community Space

● Fork us!● Meet us!

● #jbosstesting channel on irc.freenode.net● Write for us!

● Share your stories – Blog! Tweet! #arquillian● Document how it works