Date post: | 26-Mar-2015 |
Category: |
Documents |
Upload: | gabriel-fowler |
View: | 214 times |
Download: | 0 times |
Unit testing in .Net
Copyright 2007 Tikal Knowledge, Ltd. | 2 |
AgendaAgenda
Introduction Visual Studio built-in support Open source frameworks Working together Unit testing in real life Summary
Copyright 2007 Tikal Knowledge, Ltd. | 3 |
Introduction: importance of unit testingIntroduction: importance of unit testing
Better software quality Faster development cycles Easier refactoring Finer granularity of commits Easier measurement of progress
Copyright 2007 Tikal Knowledge, Ltd. | 4 |
Challenges of Unit TestingChallenges of Unit Testing
Why did not you create (enough) unit test in your last project?
We barely have time to write code, no spare time to waste on tests
Our code runs in a complicated container and cannot be tested alone
Input format is complex and it's hard to create one for a test
Output format is complex and it's hard to verify one for a test
Copyright 2007 Tikal Knowledge, Ltd. | 5 |
Challenges of Unit TestingChallenges of Unit Testing
Why did not you create (enough) unit test in your last project?
We barely have time to write code, no spare time to waste on tests
Our code runs in a complicated container and cannot be tested alone
Input format is complex and it's hard to create one for a test
Output format is complex and it's hard to verify one for a test
We have enough open bugs already, didn't want to find even more with new tests
Copyright 2007 Tikal Knowledge, Ltd. | 6 |
Importance of toolsImportance of tools
We barely have time to write code, no spare time to waste on tests
[Test] is easier than main! Our code runs in a complicated container and cannot be
tested alone Input format is complex and it's hard to create one for a
test Output format is complex and it's hard to verify one for a
test We have enough open bugs already, didn't want to find
even more with new tests
Copyright 2007 Tikal Knowledge, Ltd. | 7 |
Importance of toolsImportance of tools
[Test] is easier than main! Our code runs in a complicated container and cannot be
tested alone
Simulate container! Input format is complex and it's hard to create one for a
test Output format is complex and it's hard to verify one for a
test We have enough open bugs already, didn't want to find
even more with new tests
Copyright 2007 Tikal Knowledge, Ltd. | 8 |
Importance of toolsImportance of tools
[Test] is easier than main! Simulate container! Input format is complex and it's hard to create one for a
test
Record actual input! Output format is complex and it's hard to verify one for a
test We have enough open bugs already, didn't want to find
even more with new tests
Copyright 2007 Tikal Knowledge, Ltd. | 9 |
Importance of toolsImportance of tools
[Test] is easier than main! Simulate container! Record actual input! Output format is complex and it's hard to verify one for a
test
Use sophisticated verifiers! We have enough open bugs already, didn't want to find
even more with new tests
Copyright 2007 Tikal Knowledge, Ltd. | 10 |
Importance of toolsImportance of tools
[Test] is easier than main! Simulate container! Record actual input! Use sophisticated verifiers! We have enough open bugs already, didn't want to find
even more with new tests
Not all bugs have to be fixed!
Copyright 2007 Tikal Knowledge, Ltd. | 11 |
AgendaAgenda
Introduction Visual Studio built-in support Open source frameworks Working together Unit testing in real life Summary
Copyright 2007 Tikal Knowledge, Ltd. | 12 |
Visual Studion built-in supportVisual Studion built-in support
Attribute based» [TestClass]» [TestMethod]
Classic Assert syntax» AssertEquals(4, 2+2)
Data driven tests» [DataSource]
Copyright 2007 Tikal Knowledge, Ltd. | 13 |
DemoDemo
Copyright 2007 Tikal Knowledge, Ltd. | 14 |
AgendaAgenda
Introduction Visual Studio built-in support Open source frameworks Working together Unit testing in real life Summary
Copyright 2007 Tikal Knowledge, Ltd. | 15 |
NUnitNUnit
Proven technology since 2002 Categories Classic and constraint based asserts
» Demo
User created contstraints» Demo
Data-driven tests» Demo
pNUnit for parallel execution» Demo
Copyright 2007 Tikal Knowledge, Ltd. | 16 |
Other .Net open source test frameworksOther .Net open source test frameworks
mbUnit aka Gallio xUnit.net csUnit
Copyright 2007 Tikal Knowledge, Ltd. | 17 |
Working together: MSTest and NUnit Working together: MSTest and NUnit cooperationcooperation
MSTest cases can run under Nunit» http://www.exactmagic.com/products/mstest/
NUnit tests can run under Team Foundation» http://www.codeplex.com/nunit4teambuild
Demo
Copyright 2007 Tikal Knowledge, Ltd. | 18 |
Unit testing in real life: how to start?Unit testing in real life: how to start?
Selecting framework Creating comfortable environment Writing first tests Improving the coverage Performance testing
Copyright 2007 Tikal Knowledge, Ltd. | 19 |
ALM and Unit TestingALM and Unit Testing
Build without tests is next to nonsense Refactoring without tests is disaster Merge without tests is gambling “Last known good” without tests is not known
Copyright 2007 Tikal Knowledge, Ltd. | 20 |
Maintaining test suitesMaintaining test suites
Before the release» Bad tests may be ignored» Known bugs are reassigned to the next version» Hopefully, some bugs will be fixed
After the release» Fix bad tests» Review known bugs, separate complex bugs into simpler
ones» Check coverage
Mid-cycle» Improve test infrastructure to lower false positives» Adopt/develop measurement tools to track team bottlenecks
Copyright 2007 Tikal Knowledge, Ltd. | 21 |
SummarySummary
Unit tests are essential With appropriate infrastructure and tools they are fun to
create and maintain Unit tests can and should speed up development Non technical reasons to use unit tests
Copyright 2007 Tikal Knowledge, Ltd. | 22 |
Q & AQ & A
Copyright 2007 Tikal Knowledge, Ltd. | 23 |
Thank youThank you