42
Testing in Java San Gabriel Valley Java Users Group http://www.sgvjug.org/ June 25, 2007 David Noble [email protected] Sr. Solutions Architect, Exist Global

Testing in Java - pudn.comread.pudn.com/downloads157/ebook/697982/Testing in Java.pdf · 2009-03-22 · 3 Scope Testing concepts, practices, tools requirements static code analysis

  • Upload
    others

  • View
    10

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Testing in Java - pudn.comread.pudn.com/downloads157/ebook/697982/Testing in Java.pdf · 2009-03-22 · 3 Scope Testing concepts, practices, tools requirements static code analysis

Testing in Java

San Gabriel Valley Java Users Group

http://www.sgvjug.org/

June 25, 2007

David [email protected]

Sr. Solutions Architect, Exist Global

Page 2: Testing in Java - pudn.comread.pudn.com/downloads157/ebook/697982/Testing in Java.pdf · 2009-03-22 · 3 Scope Testing concepts, practices, tools requirements static code analysis

2

Goal

Motivate excellence in testingwith concepts, practices, and tools

Page 3: Testing in Java - pudn.comread.pudn.com/downloads157/ebook/697982/Testing in Java.pdf · 2009-03-22 · 3 Scope Testing concepts, practices, tools requirements static code analysis

3

Scope

Testingconcepts,practices,

tools

requirements

static codeanalysis

debuggingprofiling

continuousintegration

qualityassurance

Page 4: Testing in Java - pudn.comread.pudn.com/downloads157/ebook/697982/Testing in Java.pdf · 2009-03-22 · 3 Scope Testing concepts, practices, tools requirements static code analysis

4

Agenda

Test-Driven Development

Terminology

Tools

Application

Discussion

Page 5: Testing in Java - pudn.comread.pudn.com/downloads157/ebook/697982/Testing in Java.pdf · 2009-03-22 · 3 Scope Testing concepts, practices, tools requirements static code analysis

5http://www.flickr.com/photos/h2oalchemist/342496829/

System ConceptSystem Concept

System System RequirementsRequirementsSystem DesignSystem Design

Detailed DesignDetailed Design

ImplementationImplementation

Test

in

Test

in

gg

Page 6: Testing in Java - pudn.comread.pudn.com/downloads157/ebook/697982/Testing in Java.pdf · 2009-03-22 · 3 Scope Testing concepts, practices, tools requirements static code analysis

DemoA Taste of TDD

Page 7: Testing in Java - pudn.comread.pudn.com/downloads157/ebook/697982/Testing in Java.pdf · 2009-03-22 · 3 Scope Testing concepts, practices, tools requirements static code analysis

7

Test-Driven Development

Add test

See also: http://www.agiledata.org/essays/tdd.html

Make small change

Commit changes

Fail

PassPass

Page 8: Testing in Java - pudn.comread.pudn.com/downloads157/ebook/697982/Testing in Java.pdf · 2009-03-22 · 3 Scope Testing concepts, practices, tools requirements static code analysis

8

Test-Driven Development

Add test

Fix bug

Commit changes

Fail

Pass

Page 9: Testing in Java - pudn.comread.pudn.com/downloads157/ebook/697982/Testing in Java.pdf · 2009-03-22 · 3 Scope Testing concepts, practices, tools requirements static code analysis

9

Test-Driven Development

Add test

Make small change

Fail

PassPass

RefactorCode

Commit changesPass

Commit changes

Page 10: Testing in Java - pudn.comread.pudn.com/downloads157/ebook/697982/Testing in Java.pdf · 2009-03-22 · 3 Scope Testing concepts, practices, tools requirements static code analysis

10

Test-Driven Development

Small steps

Frequent check-ins

Page 11: Testing in Java - pudn.comread.pudn.com/downloads157/ebook/697982/Testing in Java.pdf · 2009-03-22 · 3 Scope Testing concepts, practices, tools requirements static code analysis

11

Test-Driven Development

Deeper than “test first”

Design for testability

Page 12: Testing in Java - pudn.comread.pudn.com/downloads157/ebook/697982/Testing in Java.pdf · 2009-03-22 · 3 Scope Testing concepts, practices, tools requirements static code analysis

12

Test-Driven Development

Unit tests as example code

Interface before implementationFunction drives form

Page 13: Testing in Java - pudn.comread.pudn.com/downloads157/ebook/697982/Testing in Java.pdf · 2009-03-22 · 3 Scope Testing concepts, practices, tools requirements static code analysis

13

Test-Driven Development

Loose coupling

Services with clear responsibilities

Mock objects

Page 14: Testing in Java - pudn.comread.pudn.com/downloads157/ebook/697982/Testing in Java.pdf · 2009-03-22 · 3 Scope Testing concepts, practices, tools requirements static code analysis

14http://flickr.com/photos/basak/227480302/

Tastethe

soup!

Page 15: Testing in Java - pudn.comread.pudn.com/downloads157/ebook/697982/Testing in Java.pdf · 2009-03-22 · 3 Scope Testing concepts, practices, tools requirements static code analysis

15

Requirements,Architecture,Design

Implementation,Deployment

RealityIntent

Page 16: Testing in Java - pudn.comread.pudn.com/downloads157/ebook/697982/Testing in Java.pdf · 2009-03-22 · 3 Scope Testing concepts, practices, tools requirements static code analysis

16

Gap!Requirements,

Architecture,Design

Implementation,Deployment

RealityIntent

Page 17: Testing in Java - pudn.comread.pudn.com/downloads157/ebook/697982/Testing in Java.pdf · 2009-03-22 · 3 Scope Testing concepts, practices, tools requirements static code analysis

17

RealityAccountability

Requirements,Architecture,Design

Testing, QA Implementation,Deployment

Intent

Page 18: Testing in Java - pudn.comread.pudn.com/downloads157/ebook/697982/Testing in Java.pdf · 2009-03-22 · 3 Scope Testing concepts, practices, tools requirements static code analysis

18

Intent

Requirements,Architecture,Design

Testing, QA Implementation,Deployment

Realit

y

Chec

k!

RealityAccountability

Page 19: Testing in Java - pudn.comread.pudn.com/downloads157/ebook/697982/Testing in Java.pdf · 2009-03-22 · 3 Scope Testing concepts, practices, tools requirements static code analysis

19

Terminology

QA – quality assuranceDo the right things

Do things right

Ensure quality standards

Page 20: Testing in Java - pudn.comread.pudn.com/downloads157/ebook/697982/Testing in Java.pdf · 2009-03-22 · 3 Scope Testing concepts, practices, tools requirements static code analysis

20

Terminology

Test – success criteriaIs it right?

Is it done?

Page 21: Testing in Java - pudn.comread.pudn.com/downloads157/ebook/697982/Testing in Java.pdf · 2009-03-22 · 3 Scope Testing concepts, practices, tools requirements static code analysis

21

Terminology

Test plan

Test case

Test suite

Test report

Test coverage

Page 22: Testing in Java - pudn.comread.pudn.com/downloads157/ebook/697982/Testing in Java.pdf · 2009-03-22 · 3 Scope Testing concepts, practices, tools requirements static code analysis

22

Terminology

Unit test

Functional test

Integration test

System test

Acceptance test

Regression test

Page 23: Testing in Java - pudn.comread.pudn.com/downloads157/ebook/697982/Testing in Java.pdf · 2009-03-22 · 3 Scope Testing concepts, practices, tools requirements static code analysis

23

Terminology

Non-functional testing

Performance test

Load test

Soak test

Page 24: Testing in Java - pudn.comread.pudn.com/downloads157/ebook/697982/Testing in Java.pdf · 2009-03-22 · 3 Scope Testing concepts, practices, tools requirements static code analysis

24

Terminology

Continuous integration

Page 25: Testing in Java - pudn.comread.pudn.com/downloads157/ebook/697982/Testing in Java.pdf · 2009-03-22 · 3 Scope Testing concepts, practices, tools requirements static code analysis

25

Tools

Eclipse, NetBeans

Ant, Maven

JUnit, TestNG

jMock, EasyMock

IDE

Build

Unit Tests

Mock Objects

Page 26: Testing in Java - pudn.comread.pudn.com/downloads157/ebook/697982/Testing in Java.pdf · 2009-03-22 · 3 Scope Testing concepts, practices, tools requirements static code analysis

26

Tools

DBUnit

Cactus

Selenium, HttpUnit

Databases

JEE Servers

Web Apps

Page 27: Testing in Java - pudn.comread.pudn.com/downloads157/ebook/697982/Testing in Java.pdf · 2009-03-22 · 3 Scope Testing concepts, practices, tools requirements static code analysis

27

Tools

Cobertura, Emma

JMeter, Eclipse TPTP

Selenium, FitNesse, Stiq

Coverage

Performance

Acceptance

Page 28: Testing in Java - pudn.comread.pudn.com/downloads157/ebook/697982/Testing in Java.pdf · 2009-03-22 · 3 Scope Testing concepts, practices, tools requirements static code analysis

28

Tools

Cruise Control,Continuum,Hudson

ContinuousIntegration

Page 29: Testing in Java - pudn.comread.pudn.com/downloads157/ebook/697982/Testing in Java.pdf · 2009-03-22 · 3 Scope Testing concepts, practices, tools requirements static code analysis

29

Tools

Eclipse, NetBeans

Ant, Maven

JUnit, TestNG

jMock, EasyMock

IDE

Build

Unit Tests

Mock Objects

DBUnit

Cactus

Selenium, HttpUnit

Databases

JEE Servers

Web Apps

Cobertura, Emma

JMeter, Eclipse TPTP

Selenium, FitNesse, Stiq

Coverage

Performance

Acceptance

Cruise Control, Continuum, HudsonContinuous Integration

Unit t

esting

Page 30: Testing in Java - pudn.comread.pudn.com/downloads157/ebook/697982/Testing in Java.pdf · 2009-03-22 · 3 Scope Testing concepts, practices, tools requirements static code analysis

DemoTools

Page 31: Testing in Java - pudn.comread.pudn.com/downloads157/ebook/697982/Testing in Java.pdf · 2009-03-22 · 3 Scope Testing concepts, practices, tools requirements static code analysis

31

Resources: SGV JUG

Web Sitehttp://sgvlug.net/mailman/listinfo/java-sig

Mailing List (Hosted by SGV Linux Users Group)http://sgvlug.net/mailman/listinfo/java-sig

[email protected]

Page 32: Testing in Java - pudn.comread.pudn.com/downloads157/ebook/697982/Testing in Java.pdf · 2009-03-22 · 3 Scope Testing concepts, practices, tools requirements static code analysis

32

Resources: TDD

Articleshttp://www.agiledata.org/essays/tdd.html

http://en.wikipedia.org/wiki/Test_driven_development

http://www.testdriven.com/modules/xoopsfaq/

http://www.artima.com/intv/testdriven.html

http://www.google.com/search?hl=en&q=test+driven+development (really!)

Page 33: Testing in Java - pudn.comread.pudn.com/downloads157/ebook/697982/Testing in Java.pdf · 2009-03-22 · 3 Scope Testing concepts, practices, tools requirements static code analysis

33

Resources: IDE & Build Tools

Eclipse IDEhttp://www.eclipse.org/

NetBeans IDEhttp://www.netbeans.org/

Anthttp://ant.apache.org/

Maven 2http://maven.apache.org/

http://www.devzuz.com/web/guest/products/resources#BBWM

Maven & Eclipsehttp://m2eclipse.codehaus.org/

Maven & Netbeanhttp://maven.apache.org/guides/mini/guide-ide-netbeans/guide-ide-netbeans.html

Page 34: Testing in Java - pudn.comread.pudn.com/downloads157/ebook/697982/Testing in Java.pdf · 2009-03-22 · 3 Scope Testing concepts, practices, tools requirements static code analysis

34

Resources: Unit Testing

JUnit Frameworkhttp://junit.org/

JUnit FAQhttp://junit.sourceforge.net/doc/faq/faq.htm

JUnit with Anthttp://ant.apache.org/manual/OptionalTasks/junit.html

http://ant.apache.org/manual/OptionalTasks/junitreport.html

JUnit with Mavenhttp://maven.apache.org/plugins/maven-surefire-plugin/

TestNG Frameworkhttp://testng.org/doc/

Jester – Mutation Testing

http://jester.sourceforge.net/

http://www.ibm.com/developerworks/java/library/j-jester/

Page 35: Testing in Java - pudn.comread.pudn.com/downloads157/ebook/697982/Testing in Java.pdf · 2009-03-22 · 3 Scope Testing concepts, practices, tools requirements static code analysis

35

Resources: Mock Objects

Mock Objects Bloghttp://mockobjects.com/

EasyMock Libraryhttp://easymock.org/

jMock Libraryhttp://jmock.org/

Page 36: Testing in Java - pudn.comread.pudn.com/downloads157/ebook/697982/Testing in Java.pdf · 2009-03-22 · 3 Scope Testing concepts, practices, tools requirements static code analysis

36

Resources: Unit & Functional

XmlUnit Libraryhttp://xmlunit.sourceforge.net/

DBUnit Libraryhttp://dbunit.sourceforge.net/

HttpUnit Libraryhttp://httpunit.sourceforge.net/

Cactus for JEE Server Codehttp://jakarta.apache.org/cactus/

Cargo for JEE Server Codehttp://cargo.codehaus.org/

Page 37: Testing in Java - pudn.comread.pudn.com/downloads157/ebook/697982/Testing in Java.pdf · 2009-03-22 · 3 Scope Testing concepts, practices, tools requirements static code analysis

37

Resources: Test Coverage

Coberturahttp://cobertura.sourceforge.net/

http://www.ibm.com/developerworks/java/library/j-cobertura/

Cobertura with Anthttp://cobertura.sourceforge.net/anttaskreference.html

Cobertura with Mavenhttp://mojo.codehaus.org/cobertura-maven-plugin/usage.html

Emmahttp://emma.sourceforge.net/

Page 38: Testing in Java - pudn.comread.pudn.com/downloads157/ebook/697982/Testing in Java.pdf · 2009-03-22 · 3 Scope Testing concepts, practices, tools requirements static code analysis

38

Resources: Perf. & Load

JUnitPerfhttp://clarkware.com/software/JUnitPerf.html

JMeterhttp://jakarta.apache.org/jmeter/

Eclipse TPTP (Test & Performance Tools Platform)http://www.eclipse.org/tptp/

Netbeans Profilerhttp://profiler.netbeans.org/

Page 39: Testing in Java - pudn.comread.pudn.com/downloads157/ebook/697982/Testing in Java.pdf · 2009-03-22 · 3 Scope Testing concepts, practices, tools requirements static code analysis

39

Resources: Acceptance Tests

Selenium for Web Appshttp://www.openqa.org/selenium/

http://www.openqa.org/selenium-ide/download.action

Automating Selenium (“Remote Control”)http://www.openqa.org/selenium-rc/

http://wiki.openqa.org/display/SRC/Selenium-RC+and+Continuous+Integration

Selenium & Mavenhttp://raibledesigns.com/rd/entry/selenium_plugin_for_maven

FitNessehttp://fitnesse.org/

Stiqhttp://storytestiq.sourceforge.net/

Page 40: Testing in Java - pudn.comread.pudn.com/downloads157/ebook/697982/Testing in Java.pdf · 2009-03-22 · 3 Scope Testing concepts, practices, tools requirements static code analysis

40

Resources: Cont. Integration

Cruise Controlhttp://cruisecontrol.sourceforge.net/

Continuumhttp://maven.apache.org/continuum/

Hudsonhttps://hudson.dev.java.net/

Page 41: Testing in Java - pudn.comread.pudn.com/downloads157/ebook/697982/Testing in Java.pdf · 2009-03-22 · 3 Scope Testing concepts, practices, tools requirements static code analysis

41

Resources: App used in Demo

Open Source Medical Record Systemhttp://www.openmrs.org/

Prerequisites: SVN, MySQL 5, Tomcat 5http://subclipse.tigris.org/update_1.2.x

http://mysql.org/

http://tomcat.apache.org/

SVN Repositoryhttp://svn.openmrs.org/openmrs/branches/alpha

InstallationEdit build.properties and properties.xml to set tomcat.user/password,

or add test/test to $CATALINA_HOME/conf/tomcat-users.xml file.

Edit build.properties and/or properties.xml to set tomcat.home file.

Comment out creation of "test" MySQL user in schema if it already exists.

Default username/password is admin/test.

Page 42: Testing in Java - pudn.comread.pudn.com/downloads157/ebook/697982/Testing in Java.pdf · 2009-03-22 · 3 Scope Testing concepts, practices, tools requirements static code analysis

Thank youTo all who participated!