NUnit

Unit testing with NUnit
Anne Lam & Chris James
CMPS 4113 – Software Engineering
April 15, 2015
Outline
•
•
•
•
What is Unit Testing?
Unit Testing Frameworks
NUnit & how it works
Conclusion
What is Unit Testing?
• Unit test - a code snippet
written to test a piece of
code
– check if code
• meets its design and
requirements
• behaves as expected
• Helps identify
algorithm/logic failures
More on Unit Testing
• Written & executed by software
developers
• Goal to segregate each part and
test them individually
• Done before integration
• Considered white-box testing
• Use “assertions” to verify
situations and conditions that
we expect to occur
Manual vs. Unit Testing
• Manual tests require • Unit tests
a tester to play role
– dramatically decrease the
number of defects in code
of end user
– less efficient
– not structured
– not repeatable
– not code
comprehensive
– improve design
– are good documentation
– reduce the cost of change
– allow refactoring
Disadvantages of Unit Testing
• Can be time-consuming and tedious
• Demands patience and thoroughness from the
development team
• Must maintain rigorous documentation
• May not be possible to test a unit for every
input scenario that will occur in real-world
environment
Good Unit Testing
•
•
•
•
•
•
•
•
•
Is fully automated
Can be run in any order if part of other tests
Runs in memory (no DB or File access, for example)
Returns the same result consistently
Runs fast
Tests a single logical concept in the system
Is readable
Is maintainable
Is trustworthy (when you see its result, you don’t need
to debug the code just to be sure)
Programming approaches
• Test-driven
development (TDD)
– Initially failing test
case defines a new
function
– Minimum code
produced to pass
– Refactor to acceptable
standards
• Extreme Programming
– “if a little testing can
eliminate a few flaws, a
lot of testing can
eliminate many more”
– Get feedback through
unit tests
• All code must have unit
tests and must
pass before it can be
released.
Unit Testing Frameworks
• JUnit – first popular
framework, based on
Java
• NUnit – C# & all .NET
languages
• cppUnit, jsUnit, PhpUnit
=> xUnit architecture
• All free
NUnit
• Open source Framework
for Microsoft .Net
• Widely used and popular
• Created by Philip Craig
• Provides a class framework
and a test runner
application
Running NUnit
• Command Line
• NUnit plug-ins and extentions
– Visual Studio or other IDE’s
– NUnit Test Adapter (free)
• NUnit GUI
– allow the selection of tests to be run, running
them, and viewing the results
Demo Video
• https://www.youtube.com/watch?v=F9Y0mw
po9j0&feature=youtu.be
Conclusion on NUnit
• Allows effective unit testing with .NET
applications
• Open-sourced & free
• Actively developed
• Testing leads to confidence, better code, and
happier clients
References
• NUnit - Home. N.p., n.d. Web. 3 Apr. 2015.
• "Testando Seu Código C# Com NUnit - Parte I." C#
Programmer. N.p., n.d. Web. 2 Apr. 2015.
• "What is Unit Testing? - Definition from
WhatIs.com." SearchSoftwareQuality. N.p., n.d. Web.
2 Apr. 2015.
• "What is Unit Testing?" ISTQB Exam Certification – Study
Material for Foundation Level, Through ISTQB and ASTQB
Exam, Certification Questions, Answers, Tutorials and More.
N.p., n.d. Web. 2 Apr. 2015.
Questions?