TDD Introduction to NUnit and Test Driven Design
What is TDD Simply: It is writing the test code before writing any other code Requires a shift in thinking Requires you to decouple from other classes
Steps to follow Don’t write any production code until you have written a failing test Don’t write any more of a test than is sufficient to fail or fail to compile. Don’t write any more production code than is sufficient to make the test pass.
NUnit Things to get started Attributes [TestFixture] [Setup] [TearDown] [ExpectedException] [Test] Assert Validate your logic by using Assert static methods
[TestFixture] Must have a public class, not sealed,  not static,  not virtual…  Looks like this: [TestFixture] public class TestHarness {
[Test] Must be a public void method Looks like this: [Test] public void MyTest() { //code here }
Assert Static methods That AreEqual NotEqual … others
Example TDD Requirements: Make accounts that can hold a monitary balance An Account can transfer funds to another account Accounts cannot transfer if it will make them go negative. We could be more complex but this is a start  
Make the failing test [TestFixture] public class TestHarness { [Test] public void CreateAccount() { Account a = new Account(); Assert.IsNotNull(a); } }
Try to Run our test Run our test, verify that it fails!  It won’t even build We met condition 1 We didn’t writing any code until we had a failing test We wrote just enough code to fail We met condition 2 It feels ridiculous…  Working in very short cycles, one or two minutes per write and fail. This suite of tests acts as a regression later on when you’re very deep in 1000s of methods.  Coverage is king!
Add the code Add just enough code to make it sufficient to pass the failing test. Pass condition 3 Looks like this: public class Account { }
Repeat over and over [Test] public void TestAccountBalance() { Account a = new Account(); a.Balance = 1200M; Assert.AreEqual(a.Balance, 1200M); }
VS Demo Pause here and do in VS
Why
Q & A Question and answers

More Related Content

PPT
Code sense
PPTX
Introduction to TDD
PDF
Revisit: Best Practices in Scala
PPSX
Ic lecture7
DOCX
Bba105 computer fundamentals..
DOCX
Bba105 computer fundamentals..
DOCX
Compiler lab final report writing
Code sense
Introduction to TDD
Revisit: Best Practices in Scala
Ic lecture7
Bba105 computer fundamentals..
Bba105 computer fundamentals..
Compiler lab final report writing

What's hot (6)

ODP
Clean Code - Part 2
PPT
Building Ifeedback
PPT
online test system
PPTX
Custom Validation PHP
PDF
Test design techniques
Clean Code - Part 2
Building Ifeedback
online test system
Custom Validation PHP
Test design techniques
Ad

Viewers also liked (20)

PPT
The Role Of National Human Rights Institutions
PPT
How To Make A Great Pbj
PDF
goodyear 8K Reports 2/18/09
PDF
How To Make A Pbj
PPT
TECNOLOGÍAS QUE USA EL COMERCIO ELECTRÓNICO
PDF
constellation energy Bylaws
PPT
Architectuur & Fotografie Opdracht 2
PPTX
Articles- 2012-2013
PDF
tesoro 10-Q Second Quarter 2006
PDF
goodyear 8K Reports 10/30/07
PDF
goodyear Annual Report 2005
PPS
The Art of Fooling Men
PPT
Chancy
PPT
RJ Evans Retained Search
PDF
Raytheon Reports 2007 Fourth Quarter Results
PDF
goodyear 10Q Reports1Q'04 10-Q/A
PDF
Computing Webinar - Creating a culture of risk management
PPTX
Informal Learning Cultural Folktales
PPT
Assignment
PDF
The Role Of National Human Rights Institutions
How To Make A Great Pbj
goodyear 8K Reports 2/18/09
How To Make A Pbj
TECNOLOGÍAS QUE USA EL COMERCIO ELECTRÓNICO
constellation energy Bylaws
Architectuur & Fotografie Opdracht 2
Articles- 2012-2013
tesoro 10-Q Second Quarter 2006
goodyear 8K Reports 10/30/07
goodyear Annual Report 2005
The Art of Fooling Men
Chancy
RJ Evans Retained Search
Raytheon Reports 2007 Fourth Quarter Results
goodyear 10Q Reports1Q'04 10-Q/A
Computing Webinar - Creating a culture of risk management
Informal Learning Cultural Folktales
Assignment
Ad

Similar to Tdd (20)

PDF
Art of unit testing: how to do it right
PDF
TDD reloaded - JUGTAA 24 Ottobre 2012
PPTX
Tdd is not about testing (OOP)
PPT
Test Driven Development
PPT
Test Driven
PDF
TDD - survival guide
PPTX
Building unit tests correctly with visual studio 2013
PDF
Unit testing (workshop)
PDF
10 Principles of Apex Testing
ODP
TDD in PHP - Memphis PHP 2011-08-25
PDF
Test Driven Development
PPTX
Fundamentals of unit testing
ODP
Testing and Testable Code
PPTX
10 Principles of Apex Testing
PPT
Acceptance Testing With Selenium
PDF
Bdd for-dso-1227123516572504-8
PPTX
The problem with tdd
PDF
TDD and Simple Design Workshop - Session 1 - March 2019
PPTX
Unit testing solid fundamentals
Art of unit testing: how to do it right
TDD reloaded - JUGTAA 24 Ottobre 2012
Tdd is not about testing (OOP)
Test Driven Development
Test Driven
TDD - survival guide
Building unit tests correctly with visual studio 2013
Unit testing (workshop)
10 Principles of Apex Testing
TDD in PHP - Memphis PHP 2011-08-25
Test Driven Development
Fundamentals of unit testing
Testing and Testable Code
10 Principles of Apex Testing
Acceptance Testing With Selenium
Bdd for-dso-1227123516572504-8
The problem with tdd
TDD and Simple Design Workshop - Session 1 - March 2019
Unit testing solid fundamentals

Tdd

  • 1. TDD Introduction to NUnit and Test Driven Design
  • 2. What is TDD Simply: It is writing the test code before writing any other code Requires a shift in thinking Requires you to decouple from other classes
  • 3. Steps to follow Don’t write any production code until you have written a failing test Don’t write any more of a test than is sufficient to fail or fail to compile. Don’t write any more production code than is sufficient to make the test pass.
  • 4. NUnit Things to get started Attributes [TestFixture] [Setup] [TearDown] [ExpectedException] [Test] Assert Validate your logic by using Assert static methods
  • 5. [TestFixture] Must have a public class, not sealed, not static, not virtual… Looks like this: [TestFixture] public class TestHarness {
  • 6. [Test] Must be a public void method Looks like this: [Test] public void MyTest() { //code here }
  • 7. Assert Static methods That AreEqual NotEqual … others
  • 8. Example TDD Requirements: Make accounts that can hold a monitary balance An Account can transfer funds to another account Accounts cannot transfer if it will make them go negative. We could be more complex but this is a start 
  • 9. Make the failing test [TestFixture] public class TestHarness { [Test] public void CreateAccount() { Account a = new Account(); Assert.IsNotNull(a); } }
  • 10. Try to Run our test Run our test, verify that it fails! It won’t even build We met condition 1 We didn’t writing any code until we had a failing test We wrote just enough code to fail We met condition 2 It feels ridiculous… Working in very short cycles, one or two minutes per write and fail. This suite of tests acts as a regression later on when you’re very deep in 1000s of methods. Coverage is king!
  • 11. Add the code Add just enough code to make it sufficient to pass the failing test. Pass condition 3 Looks like this: public class Account { }
  • 12. Repeat over and over [Test] public void TestAccountBalance() { Account a = new Account(); a.Balance = 1200M; Assert.AreEqual(a.Balance, 1200M); }
  • 13. VS Demo Pause here and do in VS
  • 14. Why
  • 15. Q & A Question and answers