Java EE Behave!!!!
Upcoming SlideShare
Loading in...5
×

Like this? Share it with your network

Share

Java EE Behave!!!!

  • 3,447 views
Uploaded on

Behavior-driven development (BDD) is an evolution of test-driven development (TDD). It shifts the vocabulary from being test-based to behavior-based and positions itself as a design philosophy.......

Behavior-driven development (BDD) is an evolution of test-driven development (TDD). It shifts the vocabulary from being test-based to behavior-based and positions itself as a design philosophy. JBehave is a Java framework for BDD, and this session explores how to write integration tests for your Java EE apps with JBehave. It also demonstrates how to leverage the Context and Dependency Injection (CDI) APIs to implement your tests.

This session is a must-see for all Java EE developers who want a better way to write integration tests aligned with the intended behavior.

More in: Technology
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Be the first to comment
No Downloads

Views

Total Views
3,447
On Slideshare
2,446
From Embeds
1,001
Number of Embeds
3

Actions

Shares
Downloads
70
Comments
0
Likes
1

Embeds 1,001

http://aaronwalker.me 923
http://lanyrd.com 72
http://localhost:4000 6

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
    No notes for slide

Transcript

  • 1. Java EE Behave!!!! Behaviour-Driven Development with Java EE Aaron Walker a.walker@base2services.com @aaronwalker http://aaronwalker.me http://www.base2services.com #jeebehavebase2Services Pty Ltd Commercial in Confidence 2010
  • 2. Agenda • What is this BDD thingy • JBehave • How to make your tests behave! • { Demo } • Java EE flavouring • { Demo } • Q &A #jeebehave base2Services Pty Ltd 2011base2Services Pty Ltd Commercial in Confidence 2010
  • 3. BDD ~ Behaviour Driven Development ~ “BDD facilitates agile development, which is an approach to develop functional software, within reasonable timeline, making everyone happy, without killing anyone, or burning down any bank.” #jeebehave base2Services Pty Ltd 2011base2Services Pty Ltd Commercial in Confidence 2010
  • 4. BDDs Core Principles • Its all behaviour “The business & technology people should be speaking the same words when referring to the same idea,there should not be any translator.” Behaviour: the addition of N values should yield the summation of them Example: the addition of 2 + 4 + 2 should yield 8 #jeebehave base2Services Pty Ltd 2011base2Services Pty Ltd Commercial in Confidence 2010
  • 5. BDDs Core Principles • The evolution of test-driven development (TDD) and acceptance-test driven design • Shifts the vocabulary from being test-based to behaviour-based • Essentially a design philosophy #jeebehave base2Services Pty Ltd 2011base2Services Pty Ltd Commercial in Confidence 2010
  • 6. Unit testing frameworks mismatch It’s all about the Behaviour #jeebehavebase2Services Pty Ltd Commercial in Confidence 2010
  • 7. Oh JBehave • a framework for Behaviour-Driven Development. • pure Java implementation • Users can specify and run plain text- based user stories • Annotation-based configuration and Steps class specifications • Dependency Injection support (more on this one later) • Tool/IDE integration • Ant, Maven, Selenium, Eclipse, IntelliJ, Netbeans #jeebehave base2Services Pty Ltd 2011base2Services Pty Ltd Commercial in Confidence 2010
  • 8. Yep....plain text #jeebehave base2Services Pty Ltd 2011base2Services Pty Ltd Commercial in Confidence 2010
  • 9. Narrative • Describes the overall intent of the story • Generally describes a single feature or use case • Should include any participating actors “In order to learn about BDD and JBehave as a JavaOne attendee I will attend session 24421- JEE Behave!” #jeebehave base2Services Pty Ltd 2011base2Services Pty Ltd Commercial in Confidence 2010
  • 10. Scenario • Describes a specific interaction • Generally fine-grained • test valid and invalid outcomes • Support for parametrisation “Scenario: User signs up with invalid data” #jeebehave base2Services Pty Ltd 2011base2Services Pty Ltd Commercial in Confidence 2010
  • 11. Given|When|Then|And • Given ... setting up system to a known state • When ... exercising an event • Then ... verifying an outcome • And ... used to chain multiple Given, When and Then statements #jeebehave base2Services Pty Ltd 2011base2Services Pty Ltd Commercial in Confidence 2010
  • 12. So where’s the Java? • Mapping Textual Scenario Steps to Java Methods via annotations • Steps instances may inherit or implement other class/ interface as required by the model of the application under test. • allows many different ways to configure Embeddable Java classes • ConfigurableEmbedder: allows the specification of the Configuration and CandidateSteps. • InjectableEmbedder: allows the injection of a fully specified Embedder. #jeebehave base2Services Pty Ltd 2011base2Services Pty Ltd Commercial in Confidence 2010
  • 13. JUnit • JUnit is supported out-of-the-box via several Embeddables implementations: • JUnitStory: provides a one-to-one mapping with the textual story via the StoryPathResolver. • JUnitStories: provides a many-to-one mapping with the textual story paths explicitly specified by overriding the storyPaths() method. #jeebehave base2Services Pty Ltd 2011base2Services Pty Ltd Commercial in Confidence 2010
  • 14. One Step at a time #jeebehave base2Services Pty Ltd 2011base2Services Pty Ltd Commercial in Confidence 2010
  • 15. And the config • Fluent API for specifying configuration #jeebehave base2Services Pty Ltd 2011base2Services Pty Ltd Commercial in Confidence 2010
  • 16. { Demo } Enough Slide-ware Show me the Code!!! #jeebehave base2Services Pty Ltd 2011base2Services Pty Ltd Commercial in Confidence 2010
  • 17. Now lets sprinkle a little bit of JEE on top #jeebehave base2Services Pty Ltd 2011base2Services Pty Ltd Commercial in Confidence 2010
  • 18. CDI/Weld • Contexts and Dependency Injection for Java • (JSR-299 included in JEE6) • Weld is the reference implementation • http://seamframework.org/Weld #jeebehave base2Services Pty Ltd 2011base2Services Pty Ltd Commercial in Confidence 2010
  • 19. JBehave CDI support • jbehave-weld module • Uses Weld Java-SE integration to bootstrap the CDI container • can inject configuration and steps using CDI annotations • greatly simplifies the configuration and management of step classes #jeebehave base2Services Pty Ltd 2011base2Services Pty Ltd Commercial in Confidence 2010
  • 20. Inject the Configuration • Use a CDI @Produces along with a @WeldConfiguration qualifier annotation • Gets automatically injected into the running scenario #jeebehave base2Services Pty Ltd 2011base2Services Pty Ltd Commercial in Confidence 2010
  • 21. What about the Steps • Simply mark Step classes with a @WeldStep annotation • They get automatically added as candidate steps • Steps can use @Inject to inject dependencies #jeebehave base2Services Pty Ltd 2011base2Services Pty Ltd Commercial in Confidence 2010
  • 22. { Demo } Show me a better way!!! #jeebehave base2Services Pty Ltd 2011base2Services Pty Ltd Commercial in Confidence 2010
  • 23. JBehave Web • JBehave Web is an extension of the JBehave framework providing a web integration layer • Features include: • Web Queue to allow generic stories to be run asynchronously via a simple web interface. • Web Runner to allow generic stories to be run synchronously via a simple web interface. • Selenium integration module to allow automation of stories for web applications using Selenium. #jeebehave base2Services Pty Ltd 2011base2Services Pty Ltd Commercial in Confidence 2010
  • 24. { Demo } Now let’s put all this together #jeebehave base2Services Pty Ltd 2011base2Services Pty Ltd Commercial in Confidence 2010
  • 25. System Integration Testing • JBehave is a good language for describing system integration • BA’s, QA’s, architects, and developers are all speaking the same language • Self documented acceptance tests #jeebehave base2Services Pty Ltd 2011base2Services Pty Ltd Commercial in Confidence 2010
  • 26. What’s Next • Custom CDI Scopes • @StoryScope, @ScenarioScope • Arquillian Integration • ??????? #jeebehave base2Services Pty Ltd 2011base2Services Pty Ltd Commercial in Confidence 2010
  • 27. Q &A • http://behaviour-driven.org/ • http://jbehave.org - JBehave project site • github.com/aaronwalker/JavaOne2011 - demo code • http://aaronwalker.me - blog • a.walker@base2services.com - email • @aaronwalker - twitter #jeebehave base2Services Pty Ltd 2011base2Services Pty Ltd Commercial in Confidence 2010