Test Driven Development - PowerPoint PPT Presentation

1 / 38
About This Presentation
Title:

Test Driven Development

Description:

Mick Knutson. About Mick Knutson. President of BASE Logic, Inc ... Mick Knutson. BASE Logic, Inc. Enterprise Architecture, Design, Mentoring & Agile Consulting ... – PowerPoint PPT presentation

Number of Views:271
Avg rating:3.0/5.0
Slides: 39
Provided by: mickkn
Category:

less

Transcript and Presenter's Notes

Title: Test Driven Development


1
Test Driven Development
  • TDD with Maven, Spring Framework, CXF and JUnit

2
Summary
  • This presentation will cover a single Maven web
    module, using the Spring framework to create a
    CXF based webservice, and testing a remote client
    with JUnit to verify the CXF contract.

3
This presentation will cover the following topics
  • Maven 2
  • CXF
  • Spring Framework
  • Spring Remoting
  • Cargo
  • Tomcat
  • JUnit

4
Takeaway
  • Attendees will take away a new insight as to how
    to create setup a Maven web module, how to add
    Spring, Cargo and CXF capabilities and how to use
    these technologies to perform unit testing with a
    test driven development lifecycle.

5
About the Author
  • Mick Knutson

6
About Mick Knutson
  • President of BASE Logic, Inc (http//www.baselogic
    .com)
  • Blog (http//www.baselogic.com/blog)
  • Won Best in Show for GoGrid.com _at_ Linux World
    2008
  • Manage Multiple Enterprise Deployments _at_ FedEx
    with gt4MIL message transactions per hour.

7
Setting Up Maven
  • Setting up a single module Maven project.

8
Maven Quick Start
  • Download Apache Maven (http//maven.apache.org)
  • Unpack Maven to C/maven
  • Install Sun JDK to c/jdks/java (NOT C/Program
    Files/java)
  • Create workspace for new project
    (c/code/ucc2009)
  • Create blank Webapp archetype (template)
  • mvn archetypecreate -DgroupIdcom.mycompany.app
    -DartifactIdmy-webapp -DarchetypeArtifactIdmaven
    -archetype-webapp
  • Open CMD prompt to c/code/ucc2009

9
Convention Over Configuration
  • Java source Directory
  • ./src/main/java/
  • Resources Directory
  • ./src/main/resources/
  • Webapp Directory
  • ./src/main/webapp/
  • Testing Source
  • ./src/test/java/
  • Testing Resources
  • ./src/test/resources/

10
Maven Quick start
  • Single Maven Module directory layout

11
Project Object Model (pom.xml)
  • Project Build Descriptor
  • Group Id
  • Artifact Id
  • Artifact Type (jar, war, ear, pom)
  • Version
  • Dependency Management
  • Plugin Management
  • Build Properties

12
Adding Spring dependencies
  • In your pom.xml,
  • add the following
  • Spring dependencies
  • Note ltpropertygt
  • ltspring.versiongt2.5.6lt/spring.versiongt

13
Spring Framework
  • Spring does many things, but when you strip it
    down to its base parts, Spring is a lightweight
    dependency injection and aspect-oriented
    container and framework.

14
Adding Spring Context
  • ./src/main/webapp/WEB-INF/applicationContext.xml

15
Adding Spring Context
  • ./src/main/webapp/WEB-INF/applicationContext-servi
    ces.xml

16
Adding CXF dependencies
  • In your pom.xml,
  • add the following
  • CXF dependencies
  • Note ltpropertygt
  • ltcxf.versiongt2.2.3lt/cxf.versiongt

17
Adding CXF Context Server entries
  • Create applicationContext-services.xml

18
Adding web.xml entries
  • Adding Spring and CXF entries

19
Adding JUnit Test Case
  • Create new Test Case
  • Instantiate Test Spring Context
  • Get Client Proxy Bean
  • Execute Proxy Methods on Bean
  • Assert outcome.

20
Adding JUnit Test
  • Create ./src/test/java//MessageWebServiceTest

21
Create Service for Test Case
  • Create Service to match our test

22
Create Service for Test Case
  • Create Service Interface
  • Annotate the Interface as _at_WebService
  • Create Service Implementation Class
  • Annotate the Class as _at_WebService defining the
    Service Interface as the endpointInterface.

23
Adding Service Interface
  • Create src/main/java//MessageService

24
Adding Service Implementation
  • Create src/main/java//MessageServiceImpl

25
Adding Spring Test Context
  • Create applicationContext-test.xml

26
Adding test.properties
  • Create src/test/resources/test.properties

27
Cargo Tomcat Plugin for Maven
  1. Compile and Package War
  2. Start embedded Tomcat container before running
    Tests
  3. Deploy war to Tomcat container
  4. Run Test Cases
  5. Assert Test Outcome
  6. Stop embedded Tomcat container after tests
    complete.

28
Cargo Tomcat Plugin
  • We want to start Tomcat with the Cargo plugin and
    deploy our webapp before running unit tests

29
Running Standalone Cargo Plugin
  • By running run-cargo-tomcat.bat, we can deploy
    our war, and verify our service endpoint in a
    browser manually

30
CXF Generated WSDL
31
Tying it all together
  • Compile and Package war
  • Start Cargo Tomcat
  • Deploy war to Tomcat
  • Run Tests
  • Assert Results
  • Stop Cargo Tomcat

32
Start Cargo, and Run Test
  • Executing mvn clean verify

33
Test Success
  • Successful Test result

34
Next Steps
  • Debug-As JUnit Tests in Eclipse
  • Remote Debugging with Eclipse
  • Use Easy Mock to stub Spring services
  • Integrate Coburtura to measure Test Code Coverage

35
Questions?
  • Any questions of comments?

36
The End
  • Thank you for your time and attention

37
Mick Knutson
  • BASE Logic, Inc.Enterprise Architecture,
    Design, Mentoring Agile ConsultingPhone.
    (866) BLiNC-411 (254-6241-1)Fax. (415)
    685-4233Website http//www.baselogic.comWebsit
    e http//www.baselogic.com/blogLinked IN
    http//www.linkedin.com/in/mickknutson

38
References
  • Source Code (http//baselogic.com/code/ucc2009/web
    app.zip)
  • Slide Deck PPT (http//baselogic.com/code/ucc2009/
    ucc.ppt)
  • Apache Maven (http//maven.apache.org)
  • Springframework (http//www.springsource.com)
  • CXF (http//cxf.apache.org)
  • Cargo Plugin (http//cargo.codehaus.org/Maven2plu
    gin)
  • SOAP UI (http//soapui.org)
Write a Comment
User Comments (0)
About PowerShow.com