21
TDD (JSAG) Presented By : Harinder Singh Bedi Friday, Dec ember 24, 2 021

TDD - Agile

Embed Size (px)

DESCRIPTION

Test driven development insight

Citation preview

Page 1: TDD - Agile

TDD (JSAG)Presented By : Harinder Singh BediApril 11, 2023

Page 2: TDD - Agile

Agenda What is TDD ? Steps to start Refactoring TDD terminology Benefits JUnit Mocktio Continuous Integration

Page 3: TDD - Agile

Test Driven Development (TDD) or Test First Development is a Software Development technique and one of the key factors of Extreme Programming Methodology.

Test Driven Development

Page 4: TDD - Agile

Development Approaches Ad hoc development Writing pseudo code first Model Driven Development (MDD) Test Driven Development (TDD)

Page 5: TDD - Agile

What is TDD ?

TDD = Test First Development + Refactoring

Page 6: TDD - Agile

How Does TDD Help Ensures that your design is clean by focusing

on creation of operations that are callable and testable

Shortens the programming feedback loop Provides detailed specification through tests Provides concrete evidence that your

software works Supports evolutionary development.

Page 7: TDD - Agile

TDD says ..

When we have a new feature to implement, we initially often think, ok how should I implement this ?

But TDD says don't do it!

"In TDD, the greater emphasis is on the usage rather than implementation"

Page 8: TDD - Agile

Steps to start TDD Analyze the requirements and write the list of tasks or features Pick a task or feature Brainstorm a list of tests for the task or feature Review the tests list and pick a test Write the test case Run the test case and see it fails to compile Write only enough code that the test case compiles Run the test and see running the code fails Write only enough code to just pass the test Refactor the production code and eliminate duplication Repeat

Page 9: TDD - Agile

When a bug is found .. First create a test case to reveal the bug Modify the production code so that the

failed test passes Finally run all the tests and make sure

your bug is fixed and covered.

Page 10: TDD - Agile

Refactoring is one of the most important parts of TDD, which means you need to refine the code design as you add new tests.

Refactoring should be done consistently as you increment the software, adding tests and production code.

Refactoring

Page 11: TDD - Agile

TDD terminology Testcase : Function or method that tests one behavior of the

code Testsuite : Set of test cases, typically grouped by fixture. Fixture : generated via a setUp() method and destroyed in

tearDown(). Assertion Function or macro allowing to compare the

expected value against the actual one. setUp() : It is a method of the Test Case class in jUnit that

can be redefined in your Test class and used to create the execution environment for all test cases in the class.

Page 12: TDD - Agile

TDD terminology Refactoring : is a source code manipulation to improving the

design of the code, without altering its external behavior. Unit : what is being tested, ranging from a single method to

a set of classes. Mock object an object implementing the same interface as,

or sub classing a class of the production code, and exhibiting a deterministic behavior.

Red bar and green bar : comes from the graphical version of JUnit, where progression bar shows the execution of the tests, and goes from green to red when a test fails.

Page 13: TDD - Agile

TDD Benefits Test Coverage : TDD does make sure that virtually every line

is executed and tested. Test Repeatability : Having the tests to back you up can give

you the courage to make changes that would otherwise be too risky to make.

Documentation : The tests describe your understanding of how the code should behave. They also describe the API. Therefore, the tests are a form of documentation.

API Design : when you write tests first, you put yourself in the position of a user of your program's API.

Page 14: TDD - Agile

TDD Benefits System Design: A module that is independently

testable is a module that is decoupled from the rest of the system.

Reduced Debugging : When you move in the tiny little steps recommended by TDD, it is hardly ever necessary to use the debugger.

Confidence : If you observe a team of developers who are practicing TDD, you will notice that every pair of developer had their code working a minute ago.

Page 15: TDD - Agile

Testing libraries Java - JUnit Ruby – Test::Unit Javascript – Test.More or JSUnit no clear standard C++ - CPPUnit PHP - PHPUnit Python - PyUnit

Page 16: TDD - Agile

TDD frameworks JUnit : It is the primary test tool for satisfying the first

requirement for a Java test framework.

Tutorial Reference : \\harinder1637\Share-d\TDD\Couse material

Mockito : is a Java-based framework for creating mock objects. It allows developers to create mocks based on classes or interfaces, specify behavior and return values for methods, and verify interactions.

Tutorial Reference : http://gojko.net/2009/10/23/mockito-in-six-easy-examples/

Page 17: TDD - Agile

Continuous integrationContinuous integration (CI) is a software engineering practice in which isolated changes are immediately tested and reported on when they are added to a larger code base. The goal of CI is to provide rapid feedback so that if a defect is introduced into the code base, it can be identified and corrected as soon as possible.

Continuous integration software tools can be used to automate the testing and build a document trail.

Page 18: TDD - Agile

Best Practices of CI• Automate the build• Create Tests to make the build self-testing• Everyone commits to the baseline every day• Every commit (to baseline) should be built• Everyone can see the results of the latest build• Automate deployment• Automation testing is absolute essential as the

system grows e.g. selenium, fitnesse

Page 19: TDD - Agile

• Having a tester in the team from day 1 is a MUST• By the time developer is ready with a feature, Tester is also

ready with scripts to break the feature• Testers should evaluate requirements and should actively

participate with product team to do analysis

TDD tests provide a way so that every developer machine can be tested. Also tests make the build self-testing.

Page 20: TDD - Agile

Software tools to support CI• Hudson – powerful software written in Java to automate build software, supports CVS, SVN, Git, Ant, Maven.

• Bamboo -- to automate build software.

• BuildMaster -- proprietary application life cycle management and continuous integration tool by Inedo.

Page 21: TDD - Agile

Questions / Queries / Feedback ?

Send to [email protected]

Thank You