Presentation is loading. Please wait.

Presentation is loading. Please wait.

Test-driven development

Similar presentations


Presentation on theme: "Test-driven development"— Presentation transcript:

1 Test-driven development
Advanced Software Engineering Dr Nuha El-Khalili

2 Test-driven development
Design Code Test TDD isn’t about testing... ...it’s about programming! Traditional development cycle Test- driven development cycle Test Code Design

3 Test-driven development
Create automated unit tests that define code requirements before writing the code itself Tests contain assertions that are either true or false. It makes the developer focus on the requirements before writing the code

4 Test-driven development

5 Test-driven development
Always start with a failing test Quickly write the simplest code needed to pass the test Remove duplication or clean up (Refactor) Repeat as needed to meet requirements Test everything that could possibly break

6 What can be tested? Valid inputs Invalid inputs
Errors, exceptions, and events Boundary conditions Everything that could possibly break!

7 Benefits Code is written for testability
Ensures that tests for every feature will be written Implement code in small steps Revert code to the last version that passed all tests Better code, in less time, with no defects

8 Benefits More modularized code with loose coupling
More maintainable code! Replace neighbors with mocks

9 But You still need integration testing and acceptance testing.
Badly written test cases will waste the effort of TDD

10 TDD vs Unit testing A Unit Test is a test of a small functional piece of code Programmers do unit testing, but: Not structured Not Repeatable Not on all your code

11 Demo Download “test driven” http://www.testdriven.net/ Supports:
Unit Testing Add-In for Microsoft Visual Studio Supports: Nunit Ncover

12 Demo Steps Open new project
Go to the solution explorer and Add a project to the existing solution called Exampletest that has the "class library" type Go to Add references: open a dialog, go to browse tab go to Nunit folder and choose the units folder and choose the dll file inside that folder In the ExampleTest class add "import Nunit.framework"

13 Demo Steps Now create another normal class and add a function there that adds two numbers, do not implement the function. Go back to the exampleTest class and add a reference to the project Add "import ProjectName“ Create a test Create a method call Assert.areequal (10, add(4,6))

14 Demo Steps Right click on the test and choose run.
Test results are down at the bottom window Test should fail Implement the function and re-test

15 See it on YouTube


Download ppt "Test-driven development"

Similar presentations


Ads by Google