Your SlideShare is downloading. ×
  • Like
Unit test
Upcoming SlideShare
Loading in...5

Thanks for flagging this SlideShare!

Oops! An error has occurred.


Now you can save presentations on your phone or tablet

Available for both IPhone and Android

Text the download link to your phone

Standard text messaging rates apply


  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Be the first to comment
    Be the first to like this
No Downloads


Total Views
On SlideShare
From Embeds
Number of Embeds



Embeds 0

No embeds

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

    No notes for slide


  • 1. Unit test Hung Nguyen
  • 2. Unit test
    • Unit Tests are tests written by the developers to test functionality as they write it.
    • Each unit test typically tests only a single class, or a small cluster of classes.
    • Unit tests are typically written using a unit testing framework, such as NUnit (automatic unit tests) .
    • Target errors not found by Unit testing :
    • - Requirements are mis-interpreted by developer.
    • - Modules don’t integrate with each other
  • 3. Why?
    • Tests Reduce Bugs in New Features
    • Tests Reduce Bugs in Existing Features
    • Tests Are Good Documentation
    • Tests Reduce the Cost of Change
    • Tests Improve Design
    • Tests Allow Refactoring
  • 4. Why
    • Tests Constrain Features
    • Tests Defend Against Other Programmers
    • Testing Is Fun
    • Testing Forces You to Slow Down and Think
    • Testing Makes Development Faster
    • Tests Reduce Fear
  • 5. Unit test
    • Dummy objects are passed around but never actually used. Usually they are just used to fill parameter lists.
    • Fake objects actually have working implementations, but usually take some shortcut which makes them not suitable for production (an in memory database is a good example).
    • Stubs provide canned answers to calls made during the test, usually not responding at all to anything outside what’s programmed in for the test. Stubs may also record information about calls, such as an email gateway stub that remembers the messages it ’sent’, or maybe only how many messages it ’sent’.
    • Mocks are what we are talking about here: objects pre-programmed with expectations which form a specification of the calls they are expected to receive.
  • 6. Stub
  • 7. Mock
  • 8. Nunit -Attributes
      • [TestFixture]
      • [Test]
      • ExpectedException(typeof(Exception))]
      • [Ignore(“message”)]
      • [SetUp]
      • [TearDown]
      • [TestFixtureSetUp]
      • [TestFixtureTearDown]
  • 9. NUnit-Example Class : namespace bank { public class Account { private float balance; public void Deposit(float amount) { balance+=amount; } public void Withdraw(float amount) { balance-=amount; } public void TransferFunds(Account destination, float amount) { } public float Balance { get{ return balance;} } } }
  • 10. NUnit-Example Test: namespace bank { using NUnit.Framework; [TestFixture] public class AccountTest { [Test] public void TransferFunds() { Account source = new Account(); source.Deposit(200.00F); Account destination = new Account(); destination.Deposit(150.00F); source.TransferFunds(destination, 100.00F); Assert.AreEqual(250.00F, destination.Balance); Assert.AreEqual(100.00F, source.Balance); } } }
  • 11. Nunit test in silverlight