Unit testing, UI testing and Test Driven Development in Visual Studio 2012
1. unit testing, ui testing, & test-
driven development in visual
studio 2012
Jon Limjap
C# MVP
2. Agenda
• Overview of Unit Testing, UI Testing and
Test Driven Development
• Unit testing UI and code in Visual Studio
2012
3. what’s up with all these tests?
overview of unit testing, ui
testing, and test driven
development
4. Let’s talk about unit testing
• What is Unit Testing?
• What is UI Testing?
• What is Test Driven Development?
5. What is a unit test?
• Code that test a single unit of functionality
(obviously!)
• A single unit is any block of code that has
ONE and only ONE responsibility:
– Method
– Function
– Class
6. What is User Interface Testing?
Using unit tests to validate user
interaction
Automates user actions: clicking and
typing
Automated UI tests allow your machine to
do repetitive tasks across an application’s
interface for you ;)
7. What is Test Driven
Development?
Using unit tests to design software
Allows change in code without fear of
changing functionality
Produces loosely coupled objects and
methods with single responsibilities
Unit tests become a tool to guide code
design
9. red
New code
Write test before implementing class
Internal workings of classes and methods
should not matter
Existing code
Write test to reproduce bug
10. green
Write least possible code to pass all tests
Take shortcuts if necessary
11. refactor
Refactor both implementation code and
test code
Change code without fear – you have
automated tests!
Remove implementation shortcuts – make
sure software design makes sense
Optimize for
design/performance/maintainability
13. Customer feedback on MS Test
• MS Test Framework Issues
– MS-Test too slow
– MS-Test missing new features
• Experience Issues
– Designed for testers and not for developers
– Not good for Agile & TDD
18. MS-Test Improvements
• Many performance and scale improvements
– Especially when you stick to “classic” unit testing
• Support for testing Async
[TestMethod]
public async Task MyAsyncTest()
{
var result = await SomeLongRunningOperation();
Assert.IsTrue( result );
}
• Proper support for 64-bit and .Net multi-targeting
• Available in Express!
22. some genuine test driven development
test driven development
with nunit and visual
studio 2012
23. Continuous Testing
• If you’re not testing you’re just compiling,
not building
• Make sure you don’t break your code and
tests – everytime you build!
24. Code Coverage
• Analyze your code
coverage with a single
click
• Analyze for selected
tests to help find how
specific tests are
covering your system
• Supports all managed
& native frameworks
25. Non C# unit testing coolness
• Unit Testing Browser-based Javascript
(via Qunit/Jasmine)
• Unit Testing Native C++ Applications
28. References
• Peter Provost:
http://channel9.msdn.com/Events/TechEd/Europe/
2012/DEV214?format=html5
• Jason Zander:
http://blogs.msdn.com/b/jasonz/archive/2012/05/
22/my-favorite-features-unit-testing-
enhancements-in-visual-studio-11.aspx
• Ben Hall:
http://blog.benhall.me.uk/2008/05/nxtgenug-
coventry-red-green-refactor.html
• Anoop Shetty:
http://anoopjshetty.wordpress.com/2012/02/08/cr
eating-test-automation-framework-using-c-
Notas do Editor
Hi my name is Jon Limjap, I’m a Microsoft Most Valuable Professional for C#,
This afternoon I’m going to discuss about unit testing, test driven development, C# and the new unit testing features of Visual Studio 2012
Ask the audience these questions:How do they define unit testing?Do they use unit testing at work?How do they define test-driven development?Do they use test driven development at work?
Unit testing is all about object oriented programmingTest driven development was designed to keep you from overdesigning and overcomplicating your API
RedNew codeWrite test before implementing classInternal workings of classes and methods should not matterExisting codeWrite test to reproduce bugGreenWrite least possible code to pass all testsTake shortcuts if necessaryRefactorRefactor both implementation code and test codeChange code without fear – you have automated tests!Remove implementation shortcuts – make sure software design makes senseOptimize for design/performance/maintainability
The main problem with Visual Studio is that it couldn’t do TDD
Whether or not you write test-first test driven development style or test-after, the best time to write your tests is while you’re writing relevant code
I don’t have time to demo all of these so we’ll only demo some
RedNew codeWrite test before implementing classInternal workings of classes and methods should not matterExisting codeWrite test to reproduce bugGreenWrite least possible code to pass all testsTake shortcuts if necessaryRefactorRefactor both implementation code and test codeChange code without fear – you have automated tests!Remove implementation shortcuts – make sure software design makes senseOptimize for design/performance/maintainability
To build is to build a working product, not a broken oneThe faster we know that we broke