Upload
randell-green
View
219
Download
6
Embed Size (px)
Citation preview
Test Driven Development Test Driven Development and NUnit Testingand NUnit Testing
-Adam Main-Adam Main
What is Test Driven What is Test Driven Development?Development?
2 Rules2 Rules• Write new code only when a test failsWrite new code only when a test fails• Eliminate duplicationEliminate duplication
Failing to compile is failing a testFailing to compile is failing a test
Basic ProcessBasic Process
1. Write a test that fails1. Write a test that fails
2. Write code to pass the test2. Write code to pass the test
3. Refactor the code3. Refactor the code
4. If the program isn’t finished, goto 4. If the program isn’t finished, goto 11
AdvantagesAdvantages
Concise and simpleConcise and simple Less manual testingLess manual testing Know specs and requirementsKnow specs and requirements Higher percent code coverageHigher percent code coverage Highly testable codeHighly testable code Coupling and cohesionCoupling and cohesion
DisadvantagesDisadvantages
High number of compilesHigh number of compiles• Wastes timeWastes time• Less thoughtLess thought
Very little designVery little design• 15-20 minutes15-20 minutes• LanguageLanguage• HardwareHardware
What is NUnit?What is NUnit?
Based off of xUnitBased off of xUnit• JUnit -JavaJUnit -Java
Basic testing frameworkBasic testing framework .NET environment.NET environment Uses metadataUses metadata Console and GUI testing appsConsole and GUI testing apps
Why NUnit?Why NUnit?
Simple InterfaceSimple Interface Constant FeedbackConstant Feedback XML resultsXML results ConfigurableConfigurable
• SubsetsSubsets• PackagesPackages• SolutionsSolutions
How do you use NUnit?How do you use NUnit?
Metadata attribute tagsMetadata attribute tags Assert library callsAssert library calls GUI or console applicationGUI or console application
What are Attribute tags?What are Attribute tags?
.NET.NET [Attribute][Attribute] MetadataMetadata ““Compilable comments”Compilable comments”
Attribute TagsAttribute Tags
[TestFixture] [TestFixture] [Test][Test] [TestFixtureSetUp][TestFixtureSetUp] [TestFixtureTearDown][TestFixtureTearDown]
More Attribute TagsMore Attribute Tags
[ExpectedException(typeof(Exceptio[ExpectedException(typeof(ExceptionType))] nType))]
[Category("Category Name")] [Category("Category Name")] [Explicit] [Explicit] [Ignore(“reason”)][Ignore(“reason”)]
What is the Assert LibraryWhat is the Assert Library
Created by NUnit teamCreated by NUnit team Static functionsStatic functions Assert classAssert class
Assert FunctionsAssert Functions
3 Basic Overloads3 Basic Overloads -Assert.IsFalse( bool condition);
-Assert.IsFalse( bool condition, string message );
-Assert.IsFalse( bool condition, string message,
object[] parms ); One Assert per testOne Assert per test
• Short circuitShort circuit• Simple and concise testsSimple and concise tests
Assert FunctionsAssert Functions
AreEqual(int actual, int expected)AreEqual(int actual, int expected) AreEqual(double actual, double expected)AreEqual(double actual, double expected) AreEqual(float actual, float expected)AreEqual(float actual, float expected) AreEqual(decimal actual, decimal expected)AreEqual(decimal actual, decimal expected) AreEqual(object actual, object expected)AreEqual(object actual, object expected) AreSame (object actual, object expected)AreSame (object actual, object expected)
Assert FunctionsAssert Functions
IsTrue( bool condition) IsTrue( bool condition) IsFalse( bool condition)IsFalse( bool condition) IsNull( object obj)IsNull( object obj) IsNotNull( object obj)IsNotNull( object obj) Fail()Fail() Ignore()Ignore()
ProjectsProjects
Load VS projects/solutionsLoad VS projects/solutions Save selected testsSave selected tests .nunit.nunit
DemoDemo
Create a simple Create a simple Use TDDUse TDD Use NUnitUse NUnit
SourcesSources
[1] NUnit - Documentation. [1] NUnit - Documentation. Retrieved March 28, 2005, from Retrieved March 28, 2005, from http://nunit.org/documentation.htmlhttp://nunit.org/documentation.html
[2] George, Boby and Laurie Williams. [2] George, Boby and Laurie Williams. An Initial Investigation of Test An Initial Investigation of Test Driven Development in IndustryDriven Development in Industry.. Retrieved March 30, 2005, from Retrieved March 30, 2005, from http://collaboration.csc.ncsu.edu/laurie/Papers/TDDpaperv8.pdfhttp://collaboration.csc.ncsu.edu/laurie/Papers/TDDpaperv8.pdf
[3] Ganssle, Jack. [3] Ganssle, Jack. XP DeconstructedXP Deconstructed. Dec 10, 2003. . Dec 10, 2003. http://www.embedded.com/showArticle.jhtml?articleID=16700086http://www.embedded.com/showArticle.jhtml?articleID=16700086
[4] Provost, Peter. [4] Provost, Peter. Test Driven Development in .NETTest Driven Development in .NET. . http://www.codeproject.com/dotnet/tdd_in_dotnet.asphttp://www.codeproject.com/dotnet/tdd_in_dotnet.asp
[5] [5] Introduction to Test Drive Development (TDD).Introduction to Test Drive Development (TDD). Retreived April Retreived April 1, 2005, from http://www.agiledata.org/essays/tdd.html1, 2005, from http://www.agiledata.org/essays/tdd.html
[6] Mugridge, Rick. [6] Mugridge, Rick. Test Driven Development and the Scientific Test Driven Development and the Scientific MethodMethod. . http://www.agiledevelopmentconference.com/2003/files/P6Paper.pdhttp://www.agiledevelopmentconference.com/2003/files/P6Paper.pdff