Your SlideShare is downloading. ×
Tdd
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

Tdd

442

Published on

0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
442
On Slideshare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
1
Comments
0
Likes
0
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide
  • Transcript

    • 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
          • Unique syntax but reads nice.
        • AreEqual
        • NotEqual
        • …others
    • 8. Example TDD
      • Requirements:
        • Make accounts that can hold a monetary 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

    ×