1 / 18

Test Driven Development and NUnit Testing

Test Driven Development and NUnit Testing. -Adam Main. What is Test Driven Development?. 2 Rules Write new code only when a test fails Eliminate duplication Failing to compile is failing a test. Basic Process. 1. Write a test that fails 2. Write code to pass the test

saul
Download Presentation

Test Driven Development and NUnit Testing

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. Test Driven Development and NUnit Testing -Adam Main

  2. What is Test Driven Development? • 2 Rules • Write new code only when a test fails • Eliminate duplication • Failing to compile is failing a test

  3. Basic Process 1. Write a test that fails 2. Write code to pass the test 3. Refactor the code 4. If the program isn’t finished, goto 1

  4. Advantages • Concise and simple • Less manual testing • Know specs and requirements • Higher percent code coverage • Highly testable code • Coupling and cohesion

  5. Disadvantages • High number of compiles • Wastes time • Less thought • Very little design • 15-20 minutes • Language • Hardware

  6. What is NUnit? • Based off of xUnit • JUnit -Java • Basic testing framework • .NET environment • Uses metadata • Console and GUI testing apps

  7. Why NUnit? • Simple Interface • Constant Feedback • XML results • Configurable • Subsets • Packages • Solutions

  8. How do you use NUnit? • Metadata attribute tags • Assert library calls • GUI or console application

  9. What are Attribute tags? • .NET • [Attribute] • Metadata • “Compilable comments”

  10. Attribute Tags • [TestFixture] • [Test] • [TestFixtureSetUp] • [TestFixtureTearDown]

  11. More Attribute Tags • [ExpectedException(typeof(ExceptionType))] • [Category("Category Name")] • [Explicit] • [Ignore(“reason”)]

  12. What is the Assert Library • Created by NUnit team • Static functions • Assert class

  13. Assert Functions • 3 Basic Overloads -Assert.IsFalse( bool condition); -Assert.IsFalse( bool condition, string message ); -Assert.IsFalse( bool condition, string message, object[] parms ); • One Assert per test • Short circuit • Simple and concise tests

  14. Assert Functions • AreEqual(int actual, int expected) • AreEqual(double actual, double expected) • AreEqual(float actual, float expected) • AreEqual(decimal actual, decimal expected) • AreEqual(object actual, object expected) • AreSame (object actual, object expected)

  15. Assert Functions • IsTrue( bool condition) • IsFalse( bool condition) • IsNull( object obj) • IsNotNull( object obj) • Fail() • Ignore()

  16. Projects • Load VS projects/solutions • Save selected tests • .nunit

  17. Demo • Create a simple • Use TDD • Use NUnit

  18. Sources • [1] NUnit - Documentation. Retrieved March 28, 2005, from http://nunit.org/documentation.html • [2] George, Boby and Laurie Williams. An Initial Investigation of Test Driven Development in Industry.Retrieved March 30, 2005, from http://collaboration.csc.ncsu.edu/laurie/Papers/TDDpaperv8.pdf • [3] Ganssle, Jack. XP Deconstructed. Dec 10, 2003. http://www.embedded.com/showArticle.jhtml?articleID=16700086 • [4] Provost, Peter. Test Driven Development in .NET. http://www.codeproject.com/dotnet/tdd_in_dotnet.asp • [5] Introduction to Test Drive Development (TDD). Retreived April 1, 2005, from http://www.agiledata.org/essays/tdd.html • [6] Mugridge, Rick. Test Driven Development and the Scientific Method. http://www.agiledevelopmentconference.com/2003/files/P6Paper.pdf

More Related