SlideShare a Scribd company logo
Introduction to Test Programming Implemented with NUnit
Excuses for not testing It takes too much time to write the tests How much time do you spend debugging code that you  or others have written? It takes too long to run the tests .  It shouldn’t. Most unit  tests should execute extremely quickly, so you should be able to run hundreds, even thousands of them in a matter of a  few seconds. It’s not my job to test my code Pray tell, what is your job, exactly? Presumably your job, at least in part, is to create working code. I don’t really know how the code is supposed to behave so  I can’t test it If you truly don’t know how the code is supposed to behave, then maybe this isn’t the time to be writing it. Maybe a prototype would be more appropriate But it compiles! It’s easy to get lulled into thinking that a successful compile is somehow a mark of approval, that you’ve passed some threshold of goodness.
12 Benefits Unit tests prove that your code actually works  You get a low-level regression-test suite  You can improve the design without breaking it  It's more fun to code with them than without  They demonstrate concrete progress  Unit tests are a form of sample code  It forces you to plan before you code  It reduces the cost of bugs  It's even better than code inspections  It virtually eliminates coder's block  Unit tests make better designs  It's faster than writing code without tests
Nunit in a nutshell
xUnit test patterns Tests should reduce risk, not introduce it. Tests should be easy to run. Tests should be easy to maintain as the system evolves around them Tests should only fail because of one reason.  (Tests should only test one thing, avoid multiple asserts for example.) There should only be one test that fails for that reason.  (this keeps your testbase maintainable) Minimize test dependencies  (no dependencies on databases, files, ui etc.)
xUnit test patterns Naming Have a descriptive name. Tests-names should read like specifications. If your names get too long you're probably testing too much. Structure Use  AAA  structure. Arrange  your context Act , do the things that need to be tested Assert , assert what you want to check  Mocks vs. Stubs The term 'Mock Objects' has become a popular one to describe special case objects that mimic real objects for testing.  Mock objects are but one form of special case test object http://martinfowler.com/articles/mocksArentStubs.html
A test is not a unit test if It talks to the database  It communicates across the network It touches the file system  It can't run at the same time as any of your other unit tests  You have to do special things to your environment (such as editing config files) to run it.
Red – Green - Refactor Red  — Write a test that expresses how you’ll use the code and what you need it to do. This test will fail, producing a red bar on many UI’s. Green  — Write enough code to get the test to pass, but no more. If you need more code, for example, to check for errors, first write another test to demonstrate that feature. For now, just write enough code to get the test to pass. Refactor   — Clean up the code to remove redundancy and improve the design. Then re-run the tests to make sure you didn’t break anything.
The Giants Martin Fowler  is an author and international speaker on software development, specializing in  object-oriented  analysis and design,  UML ,  patterns , and  agile software development  methodologies, including  extreme programming .  Fowler is a member of the  Agile Alliance  and helped create the  Manifesto for Agile Software Development  in 2001. He popularized the term  Dependency Injection [2]  as a form of  Inversion of Control . Kent Beck  is an American  software engineer  and the creator of  Extreme Programming [1]  and  Test Driven Development . Beck was one of the 17 original signatories of the  Agile Manifesto  in 2001. He has pioneered  software design patterns , the rediscovery of  Test-driven development , along with  Erich Gamma  created the  JUnit   unit testing  framework.

More Related Content

PPTX
A Brief Introduction to Test-Driven Development
PPTX
Test Driven Development
PPT
Test Driven Development
PPTX
Test-Driven Development In Action
PPT
Automated Unit Testing and TDD
PPT
What Software Quality Assurance Means to Me
PPTX
JavaScript Unit Testing
PPTX
Testing JavaScript Applications
A Brief Introduction to Test-Driven Development
Test Driven Development
Test Driven Development
Test-Driven Development In Action
Automated Unit Testing and TDD
What Software Quality Assurance Means to Me
JavaScript Unit Testing
Testing JavaScript Applications

What's hot (20)

PDF
Alexandru Bolboaca - Unit Testing from the Trenches
PDF
TDD Workshop UTN 2012
PDF
Test Driven Development
PPT
TDD (Test Driven Design)
PPTX
Test Driven Development
PPT
Test Driven Development
PPTX
Continuous Integration: Finding problems soonest
PPT
Test driven-development
PPTX
Unit tests benefits
PPT
Unit Testing, TDD and the Walking Skeleton
PPTX
Testing & should i do it
PPTX
Test Driven Development (TDD) Preso 360|Flex 2010
PDF
Getting started with Test Driven Development
PPT
Unit testing
PPT
Test Driven Development
PPT
Unit Testing
PPTX
2016 10-04: tdd++: tdd made easier
PPT
Why Do User Research And Usability Testing
PPT
Test Driven Development - Overview and Adoption
Alexandru Bolboaca - Unit Testing from the Trenches
TDD Workshop UTN 2012
Test Driven Development
TDD (Test Driven Design)
Test Driven Development
Test Driven Development
Continuous Integration: Finding problems soonest
Test driven-development
Unit tests benefits
Unit Testing, TDD and the Walking Skeleton
Testing & should i do it
Test Driven Development (TDD) Preso 360|Flex 2010
Getting started with Test Driven Development
Unit testing
Test Driven Development
Unit Testing
2016 10-04: tdd++: tdd made easier
Why Do User Research And Usability Testing
Test Driven Development - Overview and Adoption
Ad

Viewers also liked (7)

PPT
Capybara
PPT
PPT
PPT
High performance Web Sites
PPT
Coaching
PPTX
Cucumber
Capybara
High performance Web Sites
Coaching
Cucumber
Ad

Similar to Introduction to test programming (20)

PPTX
assertYourself - Breaking the Theories and Assumptions of Unit Testing in Flex
PDF
Test Driven Development (TDD)
PPT
Why test with flex unit
PPS
Unit Testing
PPTX
Test Driven Development
PPTX
Test-driven development & Behavior-driven development basics
PPT
Test-Driven Development
PPTX
Unit Testing Full@
PDF
Software Development Standard Operating Procedure
PPT
Bridging the communication gap
PPTX
Automated tests
PPTX
TDD Best Practices
PPTX
Topic production code
PPS
Why Unit Testingl
PPS
Why Unit Testingl
PPS
Why unit testingl
DOCX
Test driven development and unit testing with examples in C++
PPT
Introduction to Test Driven Development
PDF
Test-Driven Developments are Inefficient; Behavior-Driven Developments are a ...
PDF
SELJE_Database_Unit_Testing.pdf
assertYourself - Breaking the Theories and Assumptions of Unit Testing in Flex
Test Driven Development (TDD)
Why test with flex unit
Unit Testing
Test Driven Development
Test-driven development & Behavior-driven development basics
Test-Driven Development
Unit Testing Full@
Software Development Standard Operating Procedure
Bridging the communication gap
Automated tests
TDD Best Practices
Topic production code
Why Unit Testingl
Why Unit Testingl
Why unit testingl
Test driven development and unit testing with examples in C++
Introduction to Test Driven Development
Test-Driven Developments are Inefficient; Behavior-Driven Developments are a ...
SELJE_Database_Unit_Testing.pdf

Recently uploaded (20)

PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PPTX
MYSQL Presentation for SQL database connectivity
PDF
MIND Revenue Release Quarter 2 2025 Press Release
PPTX
sap open course for s4hana steps from ECC to s4
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PDF
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
PDF
Network Security Unit 5.pdf for BCA BBA.
PPTX
Programs and apps: productivity, graphics, security and other tools
PPTX
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
PDF
Approach and Philosophy of On baking technology
PDF
NewMind AI Weekly Chronicles - August'25 Week I
PPTX
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
PDF
Encapsulation theory and applications.pdf
PDF
Encapsulation_ Review paper, used for researhc scholars
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
PPTX
Cloud computing and distributed systems.
PDF
Unlocking AI with Model Context Protocol (MCP)
PDF
Review of recent advances in non-invasive hemoglobin estimation
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
MYSQL Presentation for SQL database connectivity
MIND Revenue Release Quarter 2 2025 Press Release
sap open course for s4hana steps from ECC to s4
Diabetes mellitus diagnosis method based random forest with bat algorithm
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
“AI and Expert System Decision Support & Business Intelligence Systems”
Network Security Unit 5.pdf for BCA BBA.
Programs and apps: productivity, graphics, security and other tools
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
Approach and Philosophy of On baking technology
NewMind AI Weekly Chronicles - August'25 Week I
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
Encapsulation theory and applications.pdf
Encapsulation_ Review paper, used for researhc scholars
The Rise and Fall of 3GPP – Time for a Sabbatical?
Cloud computing and distributed systems.
Unlocking AI with Model Context Protocol (MCP)
Review of recent advances in non-invasive hemoglobin estimation

Introduction to test programming

  • 1. Introduction to Test Programming Implemented with NUnit
  • 2. Excuses for not testing It takes too much time to write the tests How much time do you spend debugging code that you or others have written? It takes too long to run the tests . It shouldn’t. Most unit tests should execute extremely quickly, so you should be able to run hundreds, even thousands of them in a matter of a few seconds. It’s not my job to test my code Pray tell, what is your job, exactly? Presumably your job, at least in part, is to create working code. I don’t really know how the code is supposed to behave so I can’t test it If you truly don’t know how the code is supposed to behave, then maybe this isn’t the time to be writing it. Maybe a prototype would be more appropriate But it compiles! It’s easy to get lulled into thinking that a successful compile is somehow a mark of approval, that you’ve passed some threshold of goodness.
  • 3. 12 Benefits Unit tests prove that your code actually works You get a low-level regression-test suite You can improve the design without breaking it It's more fun to code with them than without They demonstrate concrete progress Unit tests are a form of sample code It forces you to plan before you code It reduces the cost of bugs It's even better than code inspections It virtually eliminates coder's block Unit tests make better designs It's faster than writing code without tests
  • 4. Nunit in a nutshell
  • 5. xUnit test patterns Tests should reduce risk, not introduce it. Tests should be easy to run. Tests should be easy to maintain as the system evolves around them Tests should only fail because of one reason. (Tests should only test one thing, avoid multiple asserts for example.) There should only be one test that fails for that reason. (this keeps your testbase maintainable) Minimize test dependencies (no dependencies on databases, files, ui etc.)
  • 6. xUnit test patterns Naming Have a descriptive name. Tests-names should read like specifications. If your names get too long you're probably testing too much. Structure Use AAA structure. Arrange your context Act , do the things that need to be tested Assert , assert what you want to check Mocks vs. Stubs The term 'Mock Objects' has become a popular one to describe special case objects that mimic real objects for testing. Mock objects are but one form of special case test object http://martinfowler.com/articles/mocksArentStubs.html
  • 7. A test is not a unit test if It talks to the database It communicates across the network It touches the file system It can't run at the same time as any of your other unit tests You have to do special things to your environment (such as editing config files) to run it.
  • 8. Red – Green - Refactor Red — Write a test that expresses how you’ll use the code and what you need it to do. This test will fail, producing a red bar on many UI’s. Green — Write enough code to get the test to pass, but no more. If you need more code, for example, to check for errors, first write another test to demonstrate that feature. For now, just write enough code to get the test to pass. Refactor — Clean up the code to remove redundancy and improve the design. Then re-run the tests to make sure you didn’t break anything.
  • 9. The Giants Martin Fowler is an author and international speaker on software development, specializing in object-oriented analysis and design, UML , patterns , and agile software development methodologies, including extreme programming . Fowler is a member of the Agile Alliance and helped create the Manifesto for Agile Software Development in 2001. He popularized the term Dependency Injection [2] as a form of Inversion of Control . Kent Beck is an American software engineer and the creator of Extreme Programming [1] and Test Driven Development . Beck was one of the 17 original signatories of the Agile Manifesto in 2001. He has pioneered software design patterns , the rediscovery of Test-driven development , along with Erich Gamma created the JUnit unit testing framework.