21
1 TDDD04 Software Testing Agile Methods Per Böhlin 2010 (based on Mariam Kamkar’s lecture notes from 2008) Department of Computer and Information Science Linköping University, Sweden [email protected] 2 Per Böhlin [email protected] Outline of the Lecture Background Extreme Programming (XP) Test-Driven Development (TDD) Refactoring Agile Software Development; Agile Testing

TDDD04 agile methods - Department of Computer and ...TDDD04/timetable/TDDD04_Agile_Methods.pdf · Refactoring Pair programming Collective ownership of ... On-site customer Coding

Embed Size (px)

Citation preview

1

TDDD04Software Testing

Agile Methods

Per Böhlin

2010

(based on Mariam Kamkar’s lecture notes from 2008)

Department of Computer and Information Science

Linköping University, Sweden

[email protected]

2

Per Böhlin

[email protected]

Outline of the Lecture

� Background

� Extreme Programming (XP)

� Test-Driven Development (TDD)

� Refactoring

� Agile Software Development; Agile Testing

2

5

Per Böhlin

[email protected]

Background

� Late 1990s:

� the field of software development was in trouble,

� projects were delivered late,

� cost much more than was expected,

� and/or did not deliver the originally requestedfeatures,

� programming was often a stressful job

� programmers were feeling overworked and

underappreciated.

6

Per Böhlin

[email protected]

Background

� 1994:� Chaos Report (Standish Group) documented that only 16

procent of projects were completed successfully.

� Follow-up report: what did successful projects look like?They were low cost, short, and done by small teams.

� 1999:� eXtreme Programming (XP): programmering

methodology; developer in the center of process (+customers); test-first philosophy.

� eXtreme programming is one of the most revolutionary movements in the history of programming

3

7

Per Böhlin

[email protected]

Background

� 2001-2002

� Test-First Development / Test-Driven Development

(TDD): a core practice of XP.

� TDD stands on ITs own

� 2001:

� Manifest for Agile Software Development

� Agile testing

8

Per Böhlin

[email protected]

Background

� 2002: Feature-Driven development (FDD)

� 2003:

� Behavior Driven Development (or BDD) It was originally

conceived in 2003 by Dan North as a response to Test Driven development (TDD).

� It is an Agile software development technique.

4

Extreme Programming (XP), Extreme Testing (XT)

10

Per Böhlin

[email protected]

Extreme Programming (XP), Extreme Testing (XT)

� XP, a new programmering methodology (software development methodology), born in the 1999 by Kent Beck.

� ”XP was likely developed to support the adoption of programming languages such as Java, Visual Basic, and C#. These object-based languages allow developers to create large, complex applications much more quickly than the traditional languages such as C, C++, Fortran, or Cobol.” (p. 177)

The art of software testing By Glenford J. Myers, Tom Badgett, Todd M. Thomas, Corey Sandler

5

11

Per Böhlin

[email protected]

Extreme Programming (XP); Extreme Testing (XT)

� The purpose of the XP is to create quality programs in short time frames

� XP tends to work best for small to medium-size development efforts in environments that have frequent specification changes and where near-instant communication is possible

� ”The primary difference of XP is that it focuses on testing. Test first instead of code first.”

12

Per Böhlin

[email protected]

Extreme Programming (XP)

� Values

� Principles

� Practices

6

13

Per Böhlin

[email protected]

The values of XP

� Communication

� Simplicity

� Feedback

� Courage

� Respect

14

Per Böhlin

[email protected]

The Principles of XP

� Humanity

� Economics

� Mutual Benefit

� Self-Similarity

� Improvement

� Deversity

� Reflection

� Flow

� Opportunity

� Redundancy

� Failure

� Quality

� Baby Steps

� Acccepted Responsibility

7

15

Per Böhlin

[email protected]

Practices of XP

� Planning and

requirements

� Small, incremental

release

� System metaphors*

� Simple design

� Continuous testing

� Refactoring

� Pair programming

� Collective ownership of

the code

� Continuous integration

� 40-hour work week

� On-site customer

� Coding standards

* Guide all development with a simple shared story of how the whole system works.

If you have a good metaphor in place, everyone on the team can tell about howthe system as a whole works.

16

Per Böhlin

[email protected]

Extreme testing (XT)

� Unit testing:� All code modules must have unit tests (defined and created)

before coding begins

� All code modules must pass unit tests before being released into production

� Acceptance testing:� Customers ( not together with developers) create the

acceptance tests from user stories

� More than one acceptance test may be needed for each user story

8

17

Per Böhlin

[email protected]

xUnit

xUnit: Collective name for Testing Frameworks for automated unit tests following a specific pattern

� SUnit - Small Talk

� JUnit - Java

� NUnit - C#

� CppUnit - C++

� phpUnit - PHP

� ... - and many more

� Setup SUT

� Exercise SUT

� Verify State/Behaviour

� Teardown (cleanup)

Test-Driven Development (TDD)

9

19

Per Böhlin

[email protected]

What is test-driven development (TDD)

� TDD is a mechanism for designing software

� TDD = TFD (test first design) + refactoring

� Red/Green/Refactor

Write Test Write Code Run Test

RefactoringPass

Fail

20

Per Böhlin

[email protected]

Limitations

TDD is difficult to use in some situations, such asgraphical user interfaces or relational databases,

where systems with complex input and output werenot designed for isolated unit testing or refactoring.

� Badly written tests (brittle tests) increase the burden of maintenance

� Require dedication

� Same programmer writes both test and implementation

10

21

Per Böhlin

[email protected]

Benefits

� Prevents scope creep

� Less and simpler code

� Low coupling and high cohesion

� More modularized, flexible and extensible

code

� Drives good design

22

Per Böhlin

[email protected]

Benefits (cont.)

� Little time spent debugging

� Lower total implementation time

� Built in support for change-checking

� Built in support for refactoring

� Easier to maintain

� General higher quality

11

Refactoring

24

Per Böhlin

[email protected]

Martin Fowler’s definition:“a change made to the internal structure of software to make it

easier to understand and cheaper to modify without changing its

observable behavior” (p. 53)

Fowler, Martin (1999) Refactoring: improving the design of

existing code. Addison Wesley Longman Inc. Westford

Massachusetts, april 2006, 18th printing.

”observable” : verified by tests

What is Refactoring

12

25

Per Böhlin

[email protected]

What is Refactoring (cont.)

Refactoring is the process of making changes toexisting, working code without changing its external behavior.

In other words, changing how it does it, but not whatit does.

The goal is to improve the internal structure.

26

Per Böhlin

[email protected]

Types of Refactoring

Two types of refactoring:

� ”Floss refactoring”

� ”Root canal refactoring”

Murphy-Hill, Emerson. Black, Andrew P. (2008) Refactoring Tools:

Fitness for Purpose. Department of Computer Science. Portland State

University. Portland, Oregon. May 7, 2008

“You perform floss refactoring to maintain healthy code, and you

perform root canal refactoring to correct unhealthy code” (p. 7)

13

27

Per Böhlin

[email protected]

� After doing the simplest thing possible to make a test pass,

we refactor to clean up,

� mostly removing duplication we introduced getting the test to pass

(magic numbers or strings)

� refactor the code to the organization’s coding convention

� To satisfy architectural, security constraints

� If we are practicing TDD, then we have the safety net of

tests in place that allows us refactor with confidence, thatrefactoring is not damaging any existing functionality

Refactoring is closely related to TDD in two ways:

28

Per Böhlin

[email protected]

� mostly removing duplication we introduced getting the test to pass (magic numbers or strings), ” everything once and only once” (Jeffries et al.),

Don’t repeat yourself” (Dave Thomas & Andrew Hunt).

� refactor the code to the organization’s coding convention

� To satisfy architectural, security constraints.

� when we perceive that the code and /or its intent isn’t clear (ex.choose better names for things, not out of the air).

� code smells: refer to characteristics of code that indicate less thanacceptable quality (ex comments, data class, duplicate code, large class,long method,...).

� If we are practicing TDD, then we have the safety net of tests in placethat allows us refactor with confidence, that refactoring is notdamaging any existing functionality

When to refactor

14

29

Per Böhlin

[email protected]

How to Refactor

� We need to have automated tests in place that will give us

feedback as to whether we’ve broken anything as we are

refactoring.

� In small steps, running the tests after each one. That way we

know exactly what caused the break: the last step we took. We

must back iout and try again.

� Use a good refactoring tool

(Java: jFactor, RefactorIt. [Eclipse], [jBuilder])

(C#: ReSharper, CodeRush, Refactor! [Visual Studio])

(C++: Refactor! [Visual Studio])

30

Per Böhlin

[email protected]

Some Refactorings

� Extract Interface

� Extract Method

� Extract Subclass

� Extract Superclass

� Inline Method

� Inline Class

� ... and many more

Fowler, Martin (1999) Refactoring: improving the design of existing

code. Addison Wesley

15

Agile Software development

Agile Testing

32

Per Böhlin

[email protected]

Manifest for Agile Software Development

We are uncovering better ways of developing software by doing it and

helping others do it. Through this work we have come to value:

Individuals and interactions over process and tools

Working software over comprehensive documentation

Customer collaboration over contract negotiation

Responding to change over following a plan

That is, while there is a value in the items on the right, we value the items on the left more

Kent Beck

Mike Beedle

Arie van Bennekum

Alistair Cockburn

Ward Cunningham

Martin Fowler

James Grenning

Jim Highsmith

Andrew Hunt

Ron Jeffries

Jon Kern

Brian Marick

Robert C. Martin

Steve Mellor

Kent Schwaber

Jeff Sutherland

Dave Thomas

2001, the above authors

16

33

Per Böhlin

[email protected]

The foraging analogy

Agility is taking many small steps, gathering as you go

� An agile project is like foraging for food in a forest

� Your objective is reached by many small steps

� You must know where to look� But planing every step is pointless

� You can (and should!) start with the low-hanging fruit

� You should know what is good to eat� So you can make choices about what is worth collecting

� You can taste new things� If they’re bad, spit them out and move on

� You can stop at any time� You decide when you have enough in the basket

Source: QSQ Tutorial Agil Testing, Dave Evans and Scott Syme

34

Per Böhlin

[email protected]

Agile Testing Quandrants

Crispin, Lisa. Gregory Janet (2008) Agile Testing: A Practical Guide for Testers and Agile Teams. Addison-Wesley

17

35

Per Böhlin

[email protected]

Example of Agile Methods

� Lean: lean manufacturing concepts ( drived from Toyota)applied to software development

� Scrum: lightweigh management framework

� Crystal: lightweight set of development practices

� eXtreme Programmin (XP): rigorous set of practices designedto keep both the code and team agile

� Dynamic System Development Method (DSDM)

� Feature-Driven Developmen (FDD)

36

Per Böhlin

[email protected]

Example of Agile Methods

� Lean and Scrum are project-centric in that they provide managers with tools to monitor, prioritize, and control projects without specifying anything about how the software is built.

� Crystal and eXtreme Programmin (XP) aredeveloper-centric in that they provide a set of good practices for a development team and less for aproject manager.

� One common combination: XP + Scrum

18

37

Per Böhlin

[email protected]

Typical process framework

High level

planing

Identify next

priority feature

Implement

feature

Deliver to

the customer

Review working practices

Wrap up &

celebrate

38

Per Böhlin

[email protected]

Lean

Principles:

� Eliminate waste (muda)

� Amplify learning

� Decide as late as possible

� Deliver as fast as possible

� Empower the team

� Build integrity in

� See the whole

Source: Mary poppendieck, TomPoppendick. Lean Software development: an Agile Toolkit.

Tools:

� feedback

� iteration

� cost of delay

� testing

� refactoring

� ....

Continous Improvement (Kaizen)

19

39

Per Böhlin

[email protected]

Scrum

The daily Scrum / Stand-up meeting

� Three questions each team member answers:

1. What have you done since the last scrum?

2. What do you plan to do before the nest scrum?

3. Wha is getting in the way?

Work allocation / Tracking progress� Product backlog

� Sprint backlog

� Burndown chart

40

Per Böhlin

[email protected]

Crystal

� The lead designer and two to seven other developers in alarge room or adjacent rooms,

� using information radiators such as whiteboards andflipcharts,

� having easy access to expert users,

� distracrios kept away,

� deliver running, tested, useable code to the users every month or two (quarterly at worst),

� reflecting and adjusting their working conventions preiodically.

Source: Alistair Cockburn, Crystal Clear.

20

41

Per Böhlin

[email protected]

Agile Synthesized

� Adapt: Embarace change. Give up on ”managing” or ”controlling”

� Get feedback: Test early, test often. Everyone tests.Customer ”accepts”.

� Delivery value: Do important features first. Reduce waste.Redusce overhead, reduce rework.

� Collaborate: co-locate team members. Whole teamthinking. Get close to the customer.

� Communicate: Information radiators. Big visible charts. Daily standup meeting.

� Continuously: Short timeboxes (”iterations” or ”sprints”)

42

Per Böhlin

[email protected]

Litterature:

� Extreme Programming Explained: Embrace ChangeBy Kent Beck

� Test-Driven Development, A practical guide.By David Astels

� Agile Testing: A Practical Guide for Testers And Agile TeamsBy Lisa Crispin, Janet Gregory

� Fit for Developing Software, Framework for Integrated TestsBy Rick Mugridge, Ward Cunningham

� Refactoring: improving the design of existing codeBy Martin Fowler

21

43

Per Böhlin

[email protected]

Summary

� Background

� Extreme Programming (XP)

� Test-Driven Development (TDD)

� Refactoring

� Agile Softwrae Development; Agile Testing