• Share
  • Email
  • Embed
  • Like
  • Save
  • Private Content
Unit test
 

Unit test

on

  • 684 views

 

Statistics

Views

Total Views
684
Views on SlideShare
684
Embed Views
0

Actions

Likes
0
Downloads
3
Comments
0

0 Embeds 0

No embeds

Accessibility

Categories

Upload Details

Uploaded via as Microsoft PowerPoint

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

    Unit test Unit test Presentation Transcript

    • Unit test Hung Nguyen
    • 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
    • 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
    • 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
    • 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.
    • Stub
    • Mock
    • Nunit -Attributes
        • [TestFixture]
        • [Test]
        • ExpectedException(typeof(Exception))]
        • [Ignore(“message”)]
        • [SetUp]
        • [TearDown]
        • [TestFixtureSetUp]
        • [TestFixtureTearDown]
    • 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;} } } }
    • 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); } } }
    • Nunit test in silverlight http://msmvps.com/blogs/theproblemsolver/archive/2008/12/02/unit-testing-in-silverlight-part-1.aspx