Your SlideShare is downloading. ×
0
Unit test
Unit test
Unit test
Unit test
Unit test
Unit test
Unit test
Unit test
Unit test
Unit test
Unit test
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

Unit test

561

Published on

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

  • Be the first to like this

No Downloads
Views
Total Views
561
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
5
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. Unit test Hung Nguyen
  2. Unit test <ul><li>Unit Tests are tests written by the developers to test functionality as they write it. </li></ul><ul><li>Each unit test typically tests only a single class, or a small cluster of classes. </li></ul><ul><li>Unit tests are typically written using a unit testing framework, such as NUnit (automatic unit tests) . </li></ul><ul><li>Target errors not found by Unit testing : </li></ul><ul><li>- Requirements are mis-interpreted by developer. </li></ul><ul><li>- Modules don’t integrate with each other </li></ul>
  3. Why? <ul><li>Tests Reduce Bugs in New Features </li></ul><ul><li>Tests Reduce Bugs in Existing Features </li></ul><ul><li>Tests Are Good Documentation </li></ul><ul><li>Tests Reduce the Cost of Change </li></ul><ul><li>Tests Improve Design </li></ul><ul><li>Tests Allow Refactoring </li></ul>
  4. Why <ul><li>Tests Constrain Features </li></ul><ul><li>Tests Defend Against Other Programmers </li></ul><ul><li>Testing Is Fun </li></ul><ul><li>Testing Forces You to Slow Down and Think </li></ul><ul><li>Testing Makes Development Faster </li></ul><ul><li>Tests Reduce Fear </li></ul>
  5. Unit test <ul><li>Dummy objects are passed around but never actually used. Usually they are just used to fill parameter lists. </li></ul><ul><li>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). </li></ul><ul><li>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’. </li></ul><ul><li>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. </li></ul>
  6. Stub
  7. Mock
  8. Nunit -Attributes <ul><ul><li>[TestFixture] </li></ul></ul><ul><ul><li>[Test] </li></ul></ul><ul><ul><li>ExpectedException(typeof(Exception))] </li></ul></ul><ul><ul><li>[Ignore(“message”)] </li></ul></ul><ul><ul><li>[SetUp] </li></ul></ul><ul><ul><li>[TearDown] </li></ul></ul><ul><ul><li>[TestFixtureSetUp] </li></ul></ul><ul><ul><li>[TestFixtureTearDown] </li></ul></ul>
  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 http://msmvps.com/blogs/theproblemsolver/archive/2008/12/02/unit-testing-in-silverlight-part-1.aspx

×