SlideShare a Scribd company logo
1 of 13
your trusted software partner
CMM
www.itsoft.com.eg
1
info@itsoft.com.eg
Level 3®
Implementing
Unit Testing Frameworks for .NET
Prepared By: Mohamed El-Deeb
Date: 24-06-2007
your trusted software partner
CMM
www.itsoft.com.eg
2
info@itsoft.com.eg
Level 3®
your trusted software partner
CMM
www.itsoft.com.eg
3
info@itsoft.com.eg
Level 3®
SetUp
your trusted software partner
CMM
www.itsoft.com.eg
4
info@itsoft.com.eg
Level 3®
How
//TearDown
account.Balance = 0;
[SetUp]
public void Init()
{
//SetUp
account = new Account();
account.Deposit(150);
//Excercise
account.Withdraw(50);
//Verify
Assert.AreEqual(account.Balance, 100);
}
[TearDown]
public void Dispose()
{
}
}
[Test]
public void TestWithdraw()
{
[TestFixture]
public class AccountTest
{
Account account;
}
your trusted software partner
CMM
www.itsoft.com.eg
5
info@itsoft.com.eg
Level 3®
How
[TestFixture]
public class AccountTest
{
[Test]
public void TestWithdraw()
{
//SetUp
Account source = new Account();
source.Deposit(200);
Account destination = new Account();
destination.Deposit(150);
//Excercise
source.TransferFunds(destination, 100);
//Verify
Assert.AreEqual(source.Balance, 100);
Assert.AreEqual(destination.Balance, 250);
}
}
your trusted software partner
CMM
www.itsoft.com.eg
6
info@itsoft.com.eg
Level 3®
Test Doubles
your trusted software partner
CMM
www.itsoft.com.eg
7
info@itsoft.com.eg
Level 3®
State verification
[TestFixture]
public class OrderStateTester
{
[Test]
public void TestOrderWithInvFound()
{
//setup - data
Warehouse warehouse = new Warehouse();
warehouse.Add("foo", 150);
Order order = new Order("foo", 50);
//setup - expectations
int expected = 150 - 50; // 100
//exercise
order.FillFrom(warehouse);
//verify
Assert.AreEqual(warehouse.GetInventory("foo“), expected);
}
}
Behavior Verification
[TestFixture]
public class OrderInteractionTester
{
Mockery mocks = new Mockery();
[Test]
public void TestOrderWithInvFound()
{
//setup - data
Warehouse warehouse =
(Warehouse)mocks.NewMock(typeof(Warehouse));
Order order = new Order("foo", 50);
//setup - expectations
using (mocks.Ordered)
{
Expect.Once.On(warehouse)
.Method("hasInventory")
.With("foo", 50)
.Will(Return.Value(true));
Expect.Once.On(warehouse)
.Method("Remove")
.With("foo", 50);
}
//exercise
order.FillFrom(warehouse);
//verify
mocks.VerifyAllExpectationsHaveBeenMet();
}
}
your trusted software partner
CMM
www.itsoft.com.eg
8
info@itsoft.com.eg
Level 3®
Exercise
your trusted software partner
CMM
www.itsoft.com.eg
9
info@itsoft.com.eg
Level 3®
Verify
PC-COF
 Partial runs are possible
 Consistent results on every test run
 Configuration is unneeded before run
 Order of tests does not matter
 Fast run time
your trusted software partner
CMM
www.itsoft.com.eg
10
info@itsoft.com.eg
Level 3®
Verify
PC-COF
 Partial runs are possible
 Consistent results on every test run
 Order of tests does not matter
 Fast run time
 Configuration is unneeded before run
your trusted software partner
CMM
www.itsoft.com.eg
11
info@itsoft.com.eg
Level 3®
Verify
 Don't inherit from classes you can't control.
Encapsulate and wrap it up.
 Make methods virtual by default.
 Don't use 'Sealed' unless you really have to.
 Add a setter to the singleton instance.
 Make sure a singleton always return an interface
rather than a concrete class.
 Use internal keyword to hide setters from
production code, but visible to test code.
 If possible, create an interface per class. You
never know when you're gonna need it.
your trusted software partner
CMM
www.itsoft.com.eg
12
info@itsoft.com.eg
Level 3®
Teardown
your trusted software partner
CMM
www.itsoft.com.eg
13
info@itsoft.com.eg
Level 3®
Teardown

More Related Content

What's hot

Unit Testing Concepts and Best Practices
Unit Testing Concepts and Best PracticesUnit Testing Concepts and Best Practices
Unit Testing Concepts and Best PracticesDerek Smith
 
Arquitetura básica de testes para seu projeto Java
Arquitetura básica de testes para seu projeto JavaArquitetura básica de testes para seu projeto Java
Arquitetura básica de testes para seu projeto JavaElias Nogueira
 
Criando uma arquitetura para seus testes de API com RestAssured
Criando uma arquitetura para seus testes de API com RestAssuredCriando uma arquitetura para seus testes de API com RestAssured
Criando uma arquitetura para seus testes de API com RestAssuredElias Nogueira
 
Automated vs manual testing
Automated vs manual testingAutomated vs manual testing
Automated vs manual testingKanoah
 
Unit tests & TDD
Unit tests & TDDUnit tests & TDD
Unit tests & TDDDror Helper
 
[기본과정] 코드 테스트와 커버리지 기본 교육(개념)
[기본과정] 코드 테스트와 커버리지 기본 교육(개념)[기본과정] 코드 테스트와 커버리지 기본 교육(개념)
[기본과정] 코드 테스트와 커버리지 기본 교육(개념)SangIn Choung
 
Unit testing best practices
Unit testing best practicesUnit testing best practices
Unit testing best practicesnickokiss
 
What is Integration Testing? | Edureka
What is Integration Testing? | EdurekaWhat is Integration Testing? | Edureka
What is Integration Testing? | EdurekaEdureka!
 
Automation Best Practices
Automation Best PracticesAutomation Best Practices
Automation Best PracticesSauce Labs
 
An introduction to unit testing
An introduction to unit testingAn introduction to unit testing
An introduction to unit testingAdam Stephensen
 
Introduction to Test Automation
Introduction to Test AutomationIntroduction to Test Automation
Introduction to Test AutomationPekka Klärck
 
Software Testing Life Cycle (STLC) | Software Testing Tutorial | Edureka
Software Testing Life Cycle (STLC) | Software Testing Tutorial | EdurekaSoftware Testing Life Cycle (STLC) | Software Testing Tutorial | Edureka
Software Testing Life Cycle (STLC) | Software Testing Tutorial | EdurekaEdureka!
 
Test Automation Strategies For Agile
Test Automation Strategies For AgileTest Automation Strategies For Agile
Test Automation Strategies For AgileNaresh Jain
 
Test Automation
Test AutomationTest Automation
Test Automationrockoder
 
Unit and integration Testing
Unit and integration TestingUnit and integration Testing
Unit and integration TestingDavid Berliner
 
Robot Framework - principais características
Robot Framework - principais característicasRobot Framework - principais características
Robot Framework - principais característicasalinebiath
 

What's hot (20)

Unit Testing Concepts and Best Practices
Unit Testing Concepts and Best PracticesUnit Testing Concepts and Best Practices
Unit Testing Concepts and Best Practices
 
Python unit testing
Python unit testingPython unit testing
Python unit testing
 
Test Automation - Keytorc Approach
Test Automation - Keytorc Approach Test Automation - Keytorc Approach
Test Automation - Keytorc Approach
 
Unit Testing
Unit TestingUnit Testing
Unit Testing
 
Arquitetura básica de testes para seu projeto Java
Arquitetura básica de testes para seu projeto JavaArquitetura básica de testes para seu projeto Java
Arquitetura básica de testes para seu projeto Java
 
Criando uma arquitetura para seus testes de API com RestAssured
Criando uma arquitetura para seus testes de API com RestAssuredCriando uma arquitetura para seus testes de API com RestAssured
Criando uma arquitetura para seus testes de API com RestAssured
 
Automated vs manual testing
Automated vs manual testingAutomated vs manual testing
Automated vs manual testing
 
Unit tests & TDD
Unit tests & TDDUnit tests & TDD
Unit tests & TDD
 
[기본과정] 코드 테스트와 커버리지 기본 교육(개념)
[기본과정] 코드 테스트와 커버리지 기본 교육(개념)[기본과정] 코드 테스트와 커버리지 기본 교육(개념)
[기본과정] 코드 테스트와 커버리지 기본 교육(개념)
 
Unit testing best practices
Unit testing best practicesUnit testing best practices
Unit testing best practices
 
What is Integration Testing? | Edureka
What is Integration Testing? | EdurekaWhat is Integration Testing? | Edureka
What is Integration Testing? | Edureka
 
Automation Best Practices
Automation Best PracticesAutomation Best Practices
Automation Best Practices
 
An introduction to unit testing
An introduction to unit testingAn introduction to unit testing
An introduction to unit testing
 
Introduction to Test Automation
Introduction to Test AutomationIntroduction to Test Automation
Introduction to Test Automation
 
Software Testing Life Cycle (STLC) | Software Testing Tutorial | Edureka
Software Testing Life Cycle (STLC) | Software Testing Tutorial | EdurekaSoftware Testing Life Cycle (STLC) | Software Testing Tutorial | Edureka
Software Testing Life Cycle (STLC) | Software Testing Tutorial | Edureka
 
Test Automation Strategies For Agile
Test Automation Strategies For AgileTest Automation Strategies For Agile
Test Automation Strategies For Agile
 
Test Automation
Test AutomationTest Automation
Test Automation
 
Testing methodology
Testing methodologyTesting methodology
Testing methodology
 
Unit and integration Testing
Unit and integration TestingUnit and integration Testing
Unit and integration Testing
 
Robot Framework - principais características
Robot Framework - principais característicasRobot Framework - principais características
Robot Framework - principais características
 

Similar to Unit Testing Frameworks .NET

Unit testing for WordPress
Unit testing for WordPressUnit testing for WordPress
Unit testing for WordPressHarshad Mane
 
Test studiowebinaraugcodedstep
Test studiowebinaraugcodedstepTest studiowebinaraugcodedstep
Test studiowebinaraugcodedstepDhananjay Kumar
 
Testes? Mas isso não aumenta o tempo de projecto? Não quero...
Testes? Mas isso não aumenta o tempo de projecto? Não quero...Testes? Mas isso não aumenta o tempo de projecto? Não quero...
Testes? Mas isso não aumenta o tempo de projecto? Não quero...Comunidade NetPonto
 
Test Automation Frameworks Final
Test Automation Frameworks   FinalTest Automation Frameworks   Final
Test Automation Frameworks FinalMargaret_Dickman
 
RDz for DevOps Webcast Series: Implementing Continuous Integration with RDz
RDz for DevOps Webcast Series: Implementing Continuous Integration with RDzRDz for DevOps Webcast Series: Implementing Continuous Integration with RDz
RDz for DevOps Webcast Series: Implementing Continuous Integration with RDzSusan Yoskin
 
Continuous Integration using Cruise Control
Continuous Integration using Cruise ControlContinuous Integration using Cruise Control
Continuous Integration using Cruise Controlelliando dias
 
AWS December 2015 Webinar Series - Continuous Delivery to Amazon EC2 Containe...
AWS December 2015 Webinar Series - Continuous Delivery to Amazon EC2 Containe...AWS December 2015 Webinar Series - Continuous Delivery to Amazon EC2 Containe...
AWS December 2015 Webinar Series - Continuous Delivery to Amazon EC2 Containe...Amazon Web Services
 
Overview of Lab Management and TFS
Overview of Lab Management and TFSOverview of Lab Management and TFS
Overview of Lab Management and TFSChris Kadel, MBA
 
OSDC 2014 Test Driven Infrastructure
OSDC 2014 Test Driven InfrastructureOSDC 2014 Test Driven Infrastructure
OSDC 2014 Test Driven InfrastructureSchlomo Schapiro
 
OSDC 2014: Schlomo Schapiro - Test Driven Infrastructure
OSDC 2014: Schlomo Schapiro -  Test Driven InfrastructureOSDC 2014: Schlomo Schapiro -  Test Driven Infrastructure
OSDC 2014: Schlomo Schapiro - Test Driven InfrastructureNETWAYS
 
Reliability Patterns for Large-Scale Automated Tests
Reliability Patterns for Large-Scale Automated TestsReliability Patterns for Large-Scale Automated Tests
Reliability Patterns for Large-Scale Automated TestsWaseem Hamshawi
 
Deploying Third Party Software
Deploying Third Party SoftwareDeploying Third Party Software
Deploying Third Party SoftwareSyAM Software
 
Advanced System Security and Digital Forensics
Advanced System Security and Digital ForensicsAdvanced System Security and Digital Forensics
Advanced System Security and Digital ForensicsDr. Ramchandra Mangrulkar
 
Exam viewassessmentsuiteuserguide version 9
Exam viewassessmentsuiteuserguide version 9Exam viewassessmentsuiteuserguide version 9
Exam viewassessmentsuiteuserguide version 9William McIntosh
 
Joomla! Testing - J!DD Germany 2016
Joomla! Testing - J!DD Germany 2016Joomla! Testing - J!DD Germany 2016
Joomla! Testing - J!DD Germany 2016Yves Hoppe
 
Server Side Template Injection by Mandeep Jadon
Server Side Template Injection by Mandeep JadonServer Side Template Injection by Mandeep Jadon
Server Side Template Injection by Mandeep JadonMandeep Jadon
 

Similar to Unit Testing Frameworks .NET (20)

Unit testing for WordPress
Unit testing for WordPressUnit testing for WordPress
Unit testing for WordPress
 
000 252
000 252000 252
000 252
 
Test studiowebinaraugcodedstep
Test studiowebinaraugcodedstepTest studiowebinaraugcodedstep
Test studiowebinaraugcodedstep
 
Testes? Mas isso não aumenta o tempo de projecto? Não quero...
Testes? Mas isso não aumenta o tempo de projecto? Não quero...Testes? Mas isso não aumenta o tempo de projecto? Não quero...
Testes? Mas isso não aumenta o tempo de projecto? Não quero...
 
Test Automation Frameworks Final
Test Automation Frameworks   FinalTest Automation Frameworks   Final
Test Automation Frameworks Final
 
RDz for DevOps Webcast Series: Implementing Continuous Integration with RDz
RDz for DevOps Webcast Series: Implementing Continuous Integration with RDzRDz for DevOps Webcast Series: Implementing Continuous Integration with RDz
RDz for DevOps Webcast Series: Implementing Continuous Integration with RDz
 
Continuous Integration using Cruise Control
Continuous Integration using Cruise ControlContinuous Integration using Cruise Control
Continuous Integration using Cruise Control
 
AWS December 2015 Webinar Series - Continuous Delivery to Amazon EC2 Containe...
AWS December 2015 Webinar Series - Continuous Delivery to Amazon EC2 Containe...AWS December 2015 Webinar Series - Continuous Delivery to Amazon EC2 Containe...
AWS December 2015 Webinar Series - Continuous Delivery to Amazon EC2 Containe...
 
Overview of Lab Management and TFS
Overview of Lab Management and TFSOverview of Lab Management and TFS
Overview of Lab Management and TFS
 
OSDC 2014 Test Driven Infrastructure
OSDC 2014 Test Driven InfrastructureOSDC 2014 Test Driven Infrastructure
OSDC 2014 Test Driven Infrastructure
 
OSDC 2014: Schlomo Schapiro - Test Driven Infrastructure
OSDC 2014: Schlomo Schapiro -  Test Driven InfrastructureOSDC 2014: Schlomo Schapiro -  Test Driven Infrastructure
OSDC 2014: Schlomo Schapiro - Test Driven Infrastructure
 
05 test infrastructure
05   test infrastructure05   test infrastructure
05 test infrastructure
 
Reliability Patterns for Large-Scale Automated Tests
Reliability Patterns for Large-Scale Automated TestsReliability Patterns for Large-Scale Automated Tests
Reliability Patterns for Large-Scale Automated Tests
 
Deploying Third Party Software
Deploying Third Party SoftwareDeploying Third Party Software
Deploying Third Party Software
 
Advanced System Security and Digital Forensics
Advanced System Security and Digital ForensicsAdvanced System Security and Digital Forensics
Advanced System Security and Digital Forensics
 
Exam viewassessmentsuiteuserguide version 9
Exam viewassessmentsuiteuserguide version 9Exam viewassessmentsuiteuserguide version 9
Exam viewassessmentsuiteuserguide version 9
 
Exam view user guide v9
Exam view user guide v9Exam view user guide v9
Exam view user guide v9
 
Joomla! Testing - J!DD Germany 2016
Joomla! Testing - J!DD Germany 2016Joomla! Testing - J!DD Germany 2016
Joomla! Testing - J!DD Germany 2016
 
Server Side Template Injection by Mandeep Jadon
Server Side Template Injection by Mandeep JadonServer Side Template Injection by Mandeep Jadon
Server Side Template Injection by Mandeep Jadon
 
PHPUnit
PHPUnitPHPUnit
PHPUnit
 

Unit Testing Frameworks .NET

  • 1. your trusted software partner CMM www.itsoft.com.eg 1 info@itsoft.com.eg Level 3® Implementing Unit Testing Frameworks for .NET Prepared By: Mohamed El-Deeb Date: 24-06-2007
  • 2. your trusted software partner CMM www.itsoft.com.eg 2 info@itsoft.com.eg Level 3®
  • 3. your trusted software partner CMM www.itsoft.com.eg 3 info@itsoft.com.eg Level 3® SetUp
  • 4. your trusted software partner CMM www.itsoft.com.eg 4 info@itsoft.com.eg Level 3® How //TearDown account.Balance = 0; [SetUp] public void Init() { //SetUp account = new Account(); account.Deposit(150); //Excercise account.Withdraw(50); //Verify Assert.AreEqual(account.Balance, 100); } [TearDown] public void Dispose() { } } [Test] public void TestWithdraw() { [TestFixture] public class AccountTest { Account account; }
  • 5. your trusted software partner CMM www.itsoft.com.eg 5 info@itsoft.com.eg Level 3® How [TestFixture] public class AccountTest { [Test] public void TestWithdraw() { //SetUp Account source = new Account(); source.Deposit(200); Account destination = new Account(); destination.Deposit(150); //Excercise source.TransferFunds(destination, 100); //Verify Assert.AreEqual(source.Balance, 100); Assert.AreEqual(destination.Balance, 250); } }
  • 6. your trusted software partner CMM www.itsoft.com.eg 6 info@itsoft.com.eg Level 3® Test Doubles
  • 7. your trusted software partner CMM www.itsoft.com.eg 7 info@itsoft.com.eg Level 3® State verification [TestFixture] public class OrderStateTester { [Test] public void TestOrderWithInvFound() { //setup - data Warehouse warehouse = new Warehouse(); warehouse.Add("foo", 150); Order order = new Order("foo", 50); //setup - expectations int expected = 150 - 50; // 100 //exercise order.FillFrom(warehouse); //verify Assert.AreEqual(warehouse.GetInventory("foo“), expected); } } Behavior Verification [TestFixture] public class OrderInteractionTester { Mockery mocks = new Mockery(); [Test] public void TestOrderWithInvFound() { //setup - data Warehouse warehouse = (Warehouse)mocks.NewMock(typeof(Warehouse)); Order order = new Order("foo", 50); //setup - expectations using (mocks.Ordered) { Expect.Once.On(warehouse) .Method("hasInventory") .With("foo", 50) .Will(Return.Value(true)); Expect.Once.On(warehouse) .Method("Remove") .With("foo", 50); } //exercise order.FillFrom(warehouse); //verify mocks.VerifyAllExpectationsHaveBeenMet(); } }
  • 8. your trusted software partner CMM www.itsoft.com.eg 8 info@itsoft.com.eg Level 3® Exercise
  • 9. your trusted software partner CMM www.itsoft.com.eg 9 info@itsoft.com.eg Level 3® Verify PC-COF  Partial runs are possible  Consistent results on every test run  Configuration is unneeded before run  Order of tests does not matter  Fast run time
  • 10. your trusted software partner CMM www.itsoft.com.eg 10 info@itsoft.com.eg Level 3® Verify PC-COF  Partial runs are possible  Consistent results on every test run  Order of tests does not matter  Fast run time  Configuration is unneeded before run
  • 11. your trusted software partner CMM www.itsoft.com.eg 11 info@itsoft.com.eg Level 3® Verify  Don't inherit from classes you can't control. Encapsulate and wrap it up.  Make methods virtual by default.  Don't use 'Sealed' unless you really have to.  Add a setter to the singleton instance.  Make sure a singleton always return an interface rather than a concrete class.  Use internal keyword to hide setters from production code, but visible to test code.  If possible, create an interface per class. You never know when you're gonna need it.
  • 12. your trusted software partner CMM www.itsoft.com.eg 12 info@itsoft.com.eg Level 3® Teardown
  • 13. your trusted software partner CMM www.itsoft.com.eg 13 info@itsoft.com.eg Level 3® Teardown