4. Test-driven Development
Similar to test-first
practice in Extreme
Programming
Designed for
product
development with
short iterations
Write failing test
code for desired
functionality
Write code to past
the test
Refactor code to
desired coding
standard
6. Write A Test
Write a failing unit test for each new
functionality
• The test must cover the requirements and how
exceptions are handled in the software product
Developer must have a correct
understanding of the functionality
• Refer to use case, domain models and details of the user
story
Write a test
Run all tests
Write some
code
Run test
Refactor
Repeat
7. Run All Tests
Ensures that the test harness is working
and the new unit test actually fails
• Pending the writing of correct program code
Write a test
Run all tests
Write some
code
Run test
Refactor
Repeat
8. Write Some Code
Based on the new functionality to be
developed, write the program code
The objective is to code enough to pass the
unit test
• Any duplicate code at this point must be refactored later
Write a test
Run all tests
Write some
code
Run test
Refactor
Repeat
9. Run Test
Run the test to verify that the written code passes
the test unit test
• If the test fails, review the code against specific requirements
and test cases and make the necessary modification
• Re-run the test
Write a test
Run all tests
Write some
code
Run test
Refactor
Repeat
10. Refactor
When the code is passing the test, refactor to the
desired standard
• Code follows coding standard
• No duplicate code
• Make design changes to improve the overall maintainability
of the system
Rerun all the tests after refactoring
• To ensure that all tests are passing
Write a test
Run all tests
Write some
code
Run test
Refactor
Repeat
11. Repeat
Repeat the cycle.
• Write a new unit test for a new functionality
Each cycle should be very short
• Few code edits and less that an hour
• A long cycle may prompt the developer to resort to
debugging
Write a test
Run all tests
Write some
code
Run test
Refactor
Repeat
12. Test Structure
Arrange
• Setup and initialize the desired state prior to testing
Act
• Execute the test against the method being tested
Assert
• Determines the outcome of the test
[TestClass]
public class HomeControllerTest
{
[TestMethod]
public void Index()
{
// Arrange
HomeController controller = new
HomeController();
// Act
ViewResult result = controller.Index() as
ViewResult;
// Assert
Assert.IsNotNull(result);
}
….
}
13. Fakes and Mocks
Isolate code
• Controls what is failing and where it is happening
Replaces other parts of the system with stubs and shims
• Stub - A class replacement with the same interface
• Shim – Used to replace the actual method call with the fake ones
21. Version Control
Management of changes to source files
Each change is marked with change set or revision number
• A revision is made to one or more source files
A change set is usually accompanied by a unique ID, timestamp, and the name of the person who
committed the revision
Changes to one or more source files can be reverted to specific version
22. Continuous Integration Testing
Continuous integration is a process wherein
the development team continuously integrate
their source files to a version control system
• Allows the team to work on the latest version of the
software
• Delays due to late integration are avoided
Use an automated build system to
continuously run automated integration tests
• Breaking changes are uncovered and fixed
• Rules can be implemented to prevent source files that
break the build from committed to the version control
system
Source Files
Version
Control
Server
Automated
Build Server
Build is broken
24. Team Foundation Server Version Control
(TFSVC)
Manage multiple revisions to source files
• Check-ins
• Branching and merging
• Shelving
Contributor
• Check out files
• Check in modified or new files
• Delete source files
• Compare source files
• Merge changes between files
25. How to Use TFSVC?
Set up development workspace
Create the version control of your app’s solution files
Create a new solution under version control
Put an existing solution to the version control
Contribute source files
Isolate risks by branching from trunk
Resolve version control conflicts
26. Set up Development Workspace
Access the Team Explorer in
Visual Studio
• Connect to a Team’s project
Map the team’s project to a
local folder
• Developer’s PC
Map the workspace to get
the project’s source files
27. Create the Version Control
Access the Source Control Explorer and
create the main trunk
Check in files to the main trunk
28. Create a New Solution Under Version
Control
Create a new project Add the project to a version control
29. Put an Existing Solution to the Version Control
Open your solution
Access the solution’s property page
and add the solution to TFSVC
30. Contribute source files (changes)
Access the pending
changes in solution or
project
Relate change set to one
or more work items
Check in the pending
changes. Adding
comment helps
32. Resolve Version Control Conflicts
Conflicts are highlighted
when checking in pending
changes
Access the Resolve Conflicts
link
Resolve conflicts by keeping
local version, server version
or merge conflicts
43. Load Test (1)
Create a load
test
Choose a
load pattern
Add a test
mix
Plug the web
performance
test
Run the load
test
Analyze the
results of the
test
44. Load Test (2)
Create a load
test
Choose a
load pattern
Add a test
mix
Plug the web
performance
test
Run the load
test
Analyze the
results of the
test
47. References
Test-driven development - http://en.wikipedia.org/wiki/Test-driven_development
http://en.wikipedia.org/wiki/Continuous_integration
http://en.wikipedia.org/wiki/Extreme_programming_practices#Continuous_integration
Use Team Foundation Version Control - http://msdn.microsoft.com/en-
us/library/ms181237(v=vs.120).aspx
Unit Test - http://msdn.microsoft.com/en-us/library/dd264975.aspx
Build Service - http://msdn.microsoft.com/en-us/library/ms181709.aspx
Performance and load testing - http://msdn.microsoft.com/en-us/library/dn250793.aspx
48. Copyright (C) 2014. Allan Spartacus Mangune
This work is licensed under a Creative Commons Attribution-
NonCommercial-ShareAlike 4.0 International License.
License URL: http://creativecommons.org/licenses/by-nc-
sa/4.0/