16
Test Driven Test Driven Development Development THEORY • FACTS • APPLICATIONS • SUPPORT ALEXEI PIVKINE • YURIY POSLAVSKYY • SWARAJ SHERGILL • QING WEI Group 2 Group 2

tem7

Embed Size (px)

Citation preview

Page 1: tem7

Test Driven DevelopmentTest Driven DevelopmentTHEORY • FACTS • APPLICATIONS • SUPPORT

ALEXEI PIVKINE • YURIY POSLAVSKYY • SWARAJ SHERGILL • QING WEI

Group 2Group 2

Page 2: tem7

• Definition and guidelines

• Applications of TDD

• Tool support in different programming languages

• Impact on development time, code quality and maintenance costs

• Possible issues: theory vs the real world

Outline

Page 3: tem7

Definition

• Software Design & Development techniqueSoftware Design & Development technique

• First introduced with Extreme Programming, but recentlyFirst introduced with Extreme Programming, but recently startedstarted gaining more attention on its owngaining more attention on its own

• Test Driven Development = Test First Development + RefactoringTest Driven Development = Test First Development + Refactoring

• Allows developer to think through the design and understand the requirementsAllows developer to think through the design and understand the requirements before writing the functional codebefore writing the functional code

Page 4: tem7

Guidelines

• The motto of test-driven development is "Red, Green, Refactor."

• Red: Create a test and make it fail.

• Green: Make the test pass by any means necessary.

• Refactor: Change the code to remove duplication in your project and to improve the design while ensuring that all tests still pass.

• The "Red, Green, Refactor" cycle is repeated very quickly for each new unit of code

Page 5: tem7

Design a Test Run the Tests Write Code

Run the TestsRefactoring

[Pass, Refactoring Finished, Development Continues]

[Pass, Need Refactoring] [Pass, Development Stops]

[Fail]

[Fail]

[Pass]

Test Driven Development Cycle

Page 6: tem7

TDD vs. Extreme Programming

• XP is a deliberate and disciplined approach to software development.XP is a deliberate and disciplined approach to software development.

• XP differs from traditional methodologies primarily in placing a higherXP differs from traditional methodologies primarily in placing a higher value on value on adaptabilityadaptability than on than on predictabilitypredictability

• TDD is an approach to code creation, not a software development methodologyTDD is an approach to code creation, not a software development methodology

• TDD first popularized as an aspect of XPTDD first popularized as an aspect of XP

• TDD and XP are more suitable for small to medium-sized projectsTDD and XP are more suitable for small to medium-sized projects

Page 7: tem7

Unit Testing

• A unit is the smallest testable part of an applicationA unit is the smallest testable part of an application

• The goal of unit testing is to isolate each part of the program and show that the The goal of unit testing is to isolate each part of the program and show that the individual parts are correct.individual parts are correct.

• Available Tools:

• JUnit for JavaJUnit for Java

• CppUnit for C++CppUnit for C++

• NUnit for .NETNUnit for .NET

• Test::Unit for RubyTest::Unit for Ruby

Page 8: tem7

Impact of TDD

Microsoft Case Study 1

• Team size: 6• Language: C/C++• Experience level: High• Location: Collocated

Findings

Page 9: tem7

Impact of TDD

Microsoft Case Study 2

• Team size: 5-8• Language: C++/C#• Experience level: Medium• Location: Collocated

Findings

Page 10: tem7

Impact of TDD

NRC Experiment

• Developers: 3rd year undergraduate computer science students• Language: Java• Experience level: Low• Location: Collocated• Application Size: Small• Results tested using 105 black box tests not available to developers

Findings

• No statistically significant improvements in average code quality• More consistent quality results – higher minimum achievable quality• Higher productivity due to higher number of produced lines of code (test + product)

Page 11: tem7

Impact of TDD

Other Case Studies

Page 12: tem7

Impact of TDD

• Requires extra upfront development time

• Requires more tests per unit of production code

• Encourages frequent regression testing

• Improves understanding of underlying requirements

• May or may not result in significant code quality improvements

Note

Results are difficult to generalize beyond specific environment

Page 13: tem7

Theory vs. Real World

Possible Benefits

• Better structured code

• Clearly defined interfaces

• Not afraid to refractor (improve complex code)

Possible Pitfalls

• Faulty tests

• Incomplete coverage

Page 14: tem7

Theory vs. Real World

• Absence of consistent and reliable data to prove that TDD brings improvements

• Resistance to change

• Business pressures

• Failure to completely embrace the approach

Page 15: tem7

Conclusion

• What is TDD?

• TDD, XP and unit testing

• Case studies

• Real world issues

To TDD or Not to TDD that is the question!

Page 16: tem7

References

• T.Bhat, N.Nagappan. Evaluating the Efficacy of Test-Driven Development: Industrial Case Studies. Available: http://research.microsoft.com/manuvir/papers/isese-fp17288-Bhat.pdf

• H.Erdogmus. On the Effectiveness of Test-first Approach to Programming. March 2005. Available: http://iit-iti.nrc-cnrc.gc.ca/iit-publications-iti/docs/NRC-47445.pdf

• Wikipedia, "Test-driven development", Wikipedia, [Online]. Available: http://en.wikipedia.org/wiki/Test-driven_development [Accessed: Feb. 23, 2007].

• Agile Data, "Introduction to Test Driven Design (TDD)", Agile Data, [Online]. Available: http://www.agiledata.org/essays/tdd.html [Accessed: Feb. 23, 2007].

• F Geisendörfer, "Test Driven Development in Real World Apps," September 10, 2006. [Online].   Available: http://www.thinkingphp.org/2006/09/10/test-driven-development-in-real-world-apps/ . [Accessed Feb. 23, 2007].

• L. Wyssocky, "Some Pitfalls of Test Drive Development," March 25, 2006. [Online]. Available: http://blog.qualityaspect.com/2006/03/25/some-pitfalls-of-test-driven-development/. [Accessed Feb. 23, 2007].

• "TDD viewpoint," January 16, 2005. [Online].   Available: http://neilthespod.spaces.live.com/blog/cns!F11ED9853AA5674B!110.entry. [Accessed Feb. 23, 2007].

• Unit Testing [Online] Available: http://en.wikipedia.org/wiki/Unit_testing [Accessed February 23, 2007]

• JUnit Framework [Online] Available: http://www.junit.org [Accessed February 23, 2007]

• CppUnit Framework [Online] Available: http://cppunit.sourceforge.net/cppunit-wiki [Accessed February 23, 2007]

• NUnit Framework [Online] Available: http://www.nunit.org/ [Accessed February 23, 2007]

• Ruby Test::Unit [Online] Available: http://www.ruby-doc.org/stdlib/libdoc/test/unit/rdoc/classes/Test/Unit.html [Accessed February 23, 2007]

• What is Extreme Programming [Online] Available: http://www.extremeprogramming.org/what.html [Accessed February 23, 2007]

• Jeffrey Palermo, “Guidelines for Test-Driven Development”, Visual Studio 2005 Technical Articles, May 2006 , [Online] Available: http://msdn2.microsoft.com/en-us/library/aa730844(VS.80).aspx [Accessed: Feb. 23, 2007].