Testing In Java

download Testing In Java

If you can't read please download the document

Transcript of Testing In Java

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

My background:Mostly C & Perl from 1990 1997Mostly Java since then.Telemetry processing, mission ops, EIS @ JPL.BPM, workflow, assorted biz apps.

Goal

Motivate excellence in testing

with concepts, practices, and tools

Goal falls within the larger context of pursuing excellence in software development.

Scope

Testingconcepts,practices,toolsrequirements

static codeanalysis

debugging

profiling

continuousintegration

qualityassurance

Agenda

Test-Driven Development

Terminology

Tools

Application

Discussion

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

System Concept

System Requirements

System Design

Detailed Design

Implementation

Testing

In traditional software development, testing is usually at the end of the schedule. If development runs late, the testing often suffers.

Demo
A Taste of TDD

Test-Driven Development

Add testSee also: http://www.agiledata.org/essays/tdd.html

Make small changeCommit changes

Fail

Pass

Pass

Test-Driven Development

Add testFix bugCommit changes

Fail

Pass

Test-Driven Development

Add testMake small change

Fail

Pass

Pass

RefactorCodeCommit changes

Pass

Commit changes

Test-Driven Development

Small steps

Frequent check-ins

Test-Driven Development

Deeper than test first

Design for testability

Test-Driven Development

Unit tests as example code

Interface before implementation

Function drives form

Test-Driven Development

Loose coupling

Services with clear responsibilities

Mock objects

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

Tastethesoup!

An old man calls the waiter over to his table."What would you like, sir?" asks the waiter."Taste the soup," he says."Is the soup too cold?" asks the waiter."Taste the soup," says the old man."Is it too salty?" asks the waiter."Taste the soup!" says the old man."Is there a fly in it?" asks the waiter."Taste the soup!" the old man insists.The waiter looks down: "There's no spoon!""Aha!" exclaims the old man.

Requirements,Architecture,DesignImplementation,DeploymentReality

Intent

Gap!

Requirements,Architecture,DesignImplementation,DeploymentReality

Intent

Reality

Accountability

Requirements,Architecture,DesignTesting, QAImplementation,DeploymentIntent

Intent

Requirements,Architecture,DesignTesting, QAImplementation,DeploymentRealityCheck!

Reality

Accountability

Terminology

QA quality assurance

Do the right things

Do things right

Ensure quality standards

Miriam-Webster:a program for the systematic monitoring and evaluation of the various aspects of a project, service, or facility to ensure that standards of quality are being met

Terminology

Test success criteria

Is it right?

Is it done?

Terminology

Test plan

Test case

Test suite

Test report

Test coverage

Test plan: documentTest case: implementation of specific test.Test suite: collection of test cases.Test report: results of running the tests.Test coverage: description of how much code (and which code) was exercised by tests.

Terminology

Unit test

Functional test

Integration test

System test

Acceptance test

Regression test

Unit test: typically at the granularity of a class.Functional test: a feature or use case.Integration test: multiple modules.System test: all the modules.Acceptance test: defined by user/customer.

Terminology

Non-functional testing

Performance test

Load test

Soak test

Non-functional testing: the -ilities.Performance test: how fast.Load test: how many.Soak test: how long.

Terminology

Continuous integration

This is an alternative to big bang integration, otherwise known as integration hell.

Tools

Eclipse, NetBeansAnt, MavenJUnit, TestNGjMock, EasyMockIDE

Build

Unit Tests

Mock Objects

Tools

DBUnitCactusSelenium, HttpUnitDatabases

JEE Servers

Web Apps

HttpUnit is better suited to situations where you want to examine the DOM at a low level. If you're looking for convenience, and don't need to get deep into the details, look at Selenium instead.

Tools

Cobertura, EmmaJMeter, Eclipse TPTPSelenium, FitNesse, StiqCoverage

Performance

Acceptance

Selenium IDE, a Firefox plugin, lets users or product managers create their own scenarios.Selenium is also useful during development, to quickly fast forward through actions to get the web application into a desired state.

Tools

Cruise Control,Continuum,HudsonContinuousIntegration

Tools

Eclipse, NetBeansAnt, MavenJUnit, TestNGjMock, EasyMockIDE

Build

Unit Tests

Mock Objects

DBUnitCactusSelenium, HttpUnitDatabases

JEE Servers

Web Apps

Cobertura, EmmaJMeter, Eclipse TPTPSelenium, FitNesse, StiqCoverage

Performance

Acceptance

Cruise Control, Continuum, HudsonContinuous Integration

Unit testing

The items in green aren't really a stack, just a collection of technology-specific libraries that can be useful for creating test cases.

Demo
Tools

Be sure to design Selenium tests so they can be repeatable. Either delete data when they are done, or always start from a fixed known state.

Resources: SGV JUG

Web Site

http://sgvlug.net/mailman/listinfo/java-sig

Mailing List (Hosted by SGV Linux Users Group)

http://sgvlug.net/mailman/listinfo/java-sig

[email protected]

Resources: TDD

Articles

http://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!)

Resources: IDE & Build Tools

Eclipse IDE

http://www.eclipse.org/

NetBeans IDE

http://www.netbeans.org/

Ant

http://ant.apache.org/

Maven 2

http://maven.apache.org/

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

Maven & Eclipse

http://m2eclipse.codehaus.org/

Maven & Netbean

http://maven.apache.org/guides/mini/guide-ide-netbeans/guide-ide-netbeans.html

Resources: Unit Testing

JUnit Framework

http://junit.org/

JUnit FAQ

http://junit.sourceforge.net/doc/faq/faq.htm

JUnit with Ant

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

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

JUnit with Maven

http://maven.apache.org/plugins/maven-surefire-plugin/

TestNG Framework

http://testng.org/doc/

Jester Mutation Testing

http://jester.sourceforge.net/

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

Resources: Mock Objects

Mock Objects Blog

http://mockobjects.com/

EasyMock Library

http://easymock.org/

jMock Library

http://jmock.org/

Resources: Unit & Functional

XmlUnit Library

http://xmlunit.sourceforge.net/

DBUnit Library

http://dbunit.sourceforge.net/

HttpUnit Library

http://httpunit.sourceforge.net/

Cactus for JEE Server Code

http://jakarta.apache.org/cactus/

Cargo for JEE Server Code

http://cargo.codehaus.org/

Resources: Test Coverage

Cobertura

http://cobertura.sourceforge.net/

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

Cobertura with Ant

http://cobertura.sourceforge.net/anttaskreference.html

Cobertura with Maven

http://mojo.codehaus.org/cobertura-maven-plugin/usage.html

Emma

http://emma.sourceforge.net/

Resources: Perf. & Load

JUnitPerf

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

JMeter

http://jakarta.apache.org/jmeter/

Eclipse TPTP (Test & Performance Tools Platform)

http://www.eclipse.org/tptp/

Netbeans Profiler

http://profiler.netbeans.org/

Resources: Acceptance Tests

Selenium for Web Apps

http://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 & Maven

http://raibledesigns.com/rd/entry/selenium_plugin_for_maven

FitNesse

http://fitnesse.org/

Stiq

http://storytestiq.sourceforge.net/

Resources: Cont. Integration

Cruise Control

http://cruisecontrol.sourceforge.net/

Continuum

http://maven.apache.org/continuum/

Hudson

https://hudson.dev.java.net/

Resources: App used in Demo

Open Source Medical Record System

http://www.openmrs.org/

Prerequisites: SVN, MySQL 5, Tomcat 5

http://subclipse.tigris.org/update_1.2.x

http://mysql.org/

http://tomcat.apache.org/

SVN Repository

http://svn.openmrs.org/openmrs/branches/alpha

Installation

Edit 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.

Thank you
To all who participated!

Click to edit the outline text format

Second Outline Level

Third Outline Level

Fourth Outline Level

Fifth Outline Level

Sixth Outline Level

Seventh Outline Level

Eighth Outline Level

Ninth Outline Level

Click to edit the title text format

Click to edit the title text format

Click to edit the outline text format

Second Outline Level

Third Outline Level

Fourth Outline Level

Fifth Outline Level

Sixth Outline Level

Seventh Outline Level

Eighth Outline Level

Ninth Outline Level