1 / 16

NUnit – A Unit Test Framework for .Net under Mono

Pavan Upadhya pavan.upadhya@hp.com. NUnit – A Unit Test Framework for .Net under Mono. Scope. Not a tutorial Gives high level picture May prompt the audience to give it a try if not already done it. Topics. A quick look at Mono. What is NUnit ? Features Writing a Unit Test

favian
Download Presentation

NUnit – A Unit Test Framework for .Net under Mono

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Pavan Upadhya pavan.upadhya@hp.com NUnit – A Unit Test Framework for .Net under Mono

  2. Scope • Not a tutorial • Gives high level picture • May prompt the audience to give it a try if not already done it.

  3. Topics • A quick look at Mono. • What is NUnit ? • Features • Writing a Unit Test • Code Examples • Pros and Cons • Conclusion

  4. Mono • The Mono project is sponsored by Novell • It is designed to implement the .NET Development Framework standard across various platforms. • It is open source code.

  5. What is NUnit? • NUnit is a unit-testing framework for all .Net languages. • It is written entirely in C#. • NUnit is much the same as all the Extreme Programming test frameworks (xUnits) • NUnit was initially ported from JUnit.

  6. Features • NUnit is simple to understand and easy to learn. • Object Oriented. • NUnit is flexible - Test code can be in any .Net language. • NUnit uses the "attribute" feature of .NET to identify tests.

  7. Features (Cont.) • NUnit provides a rich set of assertions. • Has both Console and GUI interface. • Can be called from NAnt as a task.

  8. Writing a Unit Test Code • Every Class must have a corresponding Test Class named TestClassName • One test method per public method, named testMethodName. • In each test method, test good results and failures • Every Test Class must have the attribute [TestFixture] • Each Test Method must have the attribute [Test]

  9. Writing a Unit Test Code (Cont..) • Other Attributes include • SetUp / Teardown • ExpectedException ( typeof( Exception)) • Explicit • Ignore

  10. Example (sample C# source) 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) { destination.Deposit(amount); Withdraw(amount); } public float Balance { get{ return balance; } } }

  11. Sampletestcode (in C#) namespace bank { using NUnit.Framework; [TestFixture] public class TestAccount { Account source, destination; [TestFixtureSetUp ] public void init() { Account source= new Account(); Account destination= new Account(); } [Test] public void TestTransferFunds() { source.Deposit(200.00F); destination.Deposit(150.00F); source.TransferFunds(destination, 100.00F); Assert.AreEqual(250.00F, destination.Balance); Assert.AreEqual(100.00F, source.Balance); } } }

  12. TestCode (Exception handling) namespace sample { using NUnit.Framework; [TestFixture] public class SuccessTests { [Test] [ExpectedException(typeof(InvalidOperationException))] public void ExpectAnException() { /* ... */ } } }

  13. Pros • NUnit is Open Source and highly extensible. • Platform independent. • Simple and easy to learn syntax. • When integrated with NAnt, can be used for incremental projects.

  14. Cons • C based extensions not available. • Lack of awareness among .Net Community.

  15. Resources • http://www.nunit.org • http://www.xprogramming.com/xpmag/acsUsingNUnit.htm#N74

  16. Questions

More Related