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 PPT
UNIT TESTING PPTUNIT TESTING PPT
UNIT TESTING PPTsuhasreddy1
 
Scrum Testing Methodology
Scrum Testing MethodologyScrum Testing Methodology
Scrum Testing MethodologyGaya1985
 
Unit tests & TDD
Unit tests & TDDUnit tests & TDD
Unit tests & TDDDror Helper
 
Beginners - Get Started With Unit Testing in .NET
Beginners - Get Started With Unit Testing in .NETBeginners - Get Started With Unit Testing in .NET
Beginners - Get Started With Unit Testing in .NETBaskar K
 
Selenium with Cucumber
Selenium  with Cucumber Selenium  with Cucumber
Selenium with Cucumber Knoldus Inc.
 
Chapter 3 SOFTWARE TESTING PROCESS
Chapter 3 SOFTWARE TESTING PROCESSChapter 3 SOFTWARE TESTING PROCESS
Chapter 3 SOFTWARE TESTING PROCESSst. michael
 
An introduction to unit testing
An introduction to unit testingAn introduction to unit testing
An introduction to unit testingAdam Stephensen
 
Unit testing JavaScript: Jasmine & karma intro
Unit testing JavaScript: Jasmine & karma introUnit testing JavaScript: Jasmine & karma intro
Unit testing JavaScript: Jasmine & karma introMaurice De Beijer [MVP]
 
Types of Software Testing
Types of Software TestingTypes of Software Testing
Types of Software TestingNishant Worah
 
Unit Testing And Mocking
Unit Testing And MockingUnit Testing And Mocking
Unit Testing And MockingJoe Wilson
 

What's hot (20)

Unit testing
Unit testing Unit testing
Unit testing
 
UNIT TESTING PPT
UNIT TESTING PPTUNIT TESTING PPT
UNIT TESTING PPT
 
Unit Testing (C#)
Unit Testing (C#)Unit Testing (C#)
Unit Testing (C#)
 
Scrum Testing Methodology
Scrum Testing MethodologyScrum Testing Methodology
Scrum Testing Methodology
 
Unit tests & TDD
Unit tests & TDDUnit tests & TDD
Unit tests & TDD
 
Beginners - Get Started With Unit Testing in .NET
Beginners - Get Started With Unit Testing in .NETBeginners - Get Started With Unit Testing in .NET
Beginners - Get Started With Unit Testing in .NET
 
Unit test
Unit testUnit test
Unit test
 
Automation testing
Automation testingAutomation testing
Automation testing
 
Selenium with Cucumber
Selenium  with Cucumber Selenium  with Cucumber
Selenium with Cucumber
 
Unit testing
Unit testingUnit testing
Unit testing
 
Chapter 3 SOFTWARE TESTING PROCESS
Chapter 3 SOFTWARE TESTING PROCESSChapter 3 SOFTWARE TESTING PROCESS
Chapter 3 SOFTWARE TESTING PROCESS
 
Workshop unit test
Workshop   unit testWorkshop   unit test
Workshop unit test
 
Angular Unit Testing
Angular Unit TestingAngular Unit Testing
Angular Unit Testing
 
An introduction to unit testing
An introduction to unit testingAn introduction to unit testing
An introduction to unit testing
 
Test Automation
Test AutomationTest Automation
Test Automation
 
Unit testing JavaScript: Jasmine & karma intro
Unit testing JavaScript: Jasmine & karma introUnit testing JavaScript: Jasmine & karma intro
Unit testing JavaScript: Jasmine & karma intro
 
Types of Software Testing
Types of Software TestingTypes of Software Testing
Types of Software Testing
 
Unit Testing
Unit TestingUnit Testing
Unit Testing
 
TDD - Agile
TDD - Agile TDD - Agile
TDD - Agile
 
Unit Testing And Mocking
Unit Testing And MockingUnit Testing And Mocking
Unit Testing And Mocking
 

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