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

Automation testing strategy, approach & planning
Automation testing  strategy, approach & planningAutomation testing  strategy, approach & planning
Automation testing strategy, approach & planning
SivaprasanthRentala1975
 
Feature driven development (FDD)
Feature driven development (FDD)Feature driven development (FDD)
Feature driven development (FDD)
LennonDukeDuero
 
Manual testing concepts course 1
Manual testing concepts course 1Manual testing concepts course 1
Manual testing concepts course 1
Raghu Kiran
 

What's hot (20)

Agile testing
Agile testingAgile testing
Agile testing
 
Test planning
Test planningTest planning
Test planning
 
Test-Driven Development
Test-Driven DevelopmentTest-Driven Development
Test-Driven Development
 
Unit Testing Concepts and Best Practices
Unit Testing Concepts and Best PracticesUnit Testing Concepts and Best Practices
Unit Testing Concepts and Best Practices
 
Automation testing strategy, approach & planning
Automation testing  strategy, approach & planningAutomation testing  strategy, approach & planning
Automation testing strategy, approach & planning
 
What is integration testing
What is integration testingWhat is integration testing
What is integration testing
 
Test Automation
Test AutomationTest Automation
Test Automation
 
Unit tests & TDD
Unit tests & TDDUnit tests & TDD
Unit tests & TDD
 
Software Testing Life Cycle – A Beginner’s Guide
Software Testing Life Cycle – A Beginner’s GuideSoftware Testing Life Cycle – A Beginner’s Guide
Software Testing Life Cycle – A Beginner’s Guide
 
ISTQB / ISEB Foundation Exam Practice - 5
ISTQB / ISEB Foundation Exam Practice - 5ISTQB / ISEB Foundation Exam Practice - 5
ISTQB / ISEB Foundation Exam Practice - 5
 
A Not-So-Serious Introduction to Test Driven Development (TDD)
A Not-So-Serious Introduction to Test Driven Development (TDD) A Not-So-Serious Introduction to Test Driven Development (TDD)
A Not-So-Serious Introduction to Test Driven Development (TDD)
 
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
 
Software testing ppt
Software testing pptSoftware testing ppt
Software testing ppt
 
Feature driven development (FDD)
Feature driven development (FDD)Feature driven development (FDD)
Feature driven development (FDD)
 
Agile Testing and Test Automation
Agile Testing and Test AutomationAgile Testing and Test Automation
Agile Testing and Test Automation
 
Software testing principles
Software testing principlesSoftware testing principles
Software testing principles
 
Manual testing concepts course 1
Manual testing concepts course 1Manual testing concepts course 1
Manual testing concepts course 1
 
Testing strategies in Software Engineering
Testing strategies in Software EngineeringTesting strategies in Software Engineering
Testing strategies in Software Engineering
 
Manual testing - Introduction to Manual Software testing
Manual testing - Introduction to Manual Software testingManual testing - Introduction to Manual Software testing
Manual testing - Introduction to Manual Software testing
 
Shift Left & Shift Right Approach in Testing
Shift Left  &  Shift Right  Approach in TestingShift Left  &  Shift Right  Approach in Testing
Shift Left & Shift Right Approach in Testing
 

Similar to xUnit

Continuous Integration using Cruise Control
Continuous Integration using Cruise ControlContinuous Integration using Cruise Control
Continuous Integration using Cruise Control
elliando dias
 
OSDC 2014 Test Driven Infrastructure
OSDC 2014 Test Driven InfrastructureOSDC 2014 Test Driven Infrastructure
OSDC 2014 Test Driven Infrastructure
Schlomo 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 Infrastructure
NETWAYS
 
Deploying Third Party Software
Deploying Third Party SoftwareDeploying Third Party Software
Deploying Third Party Software
SyAM Software
 

Similar to xUnit (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
 

xUnit

  • 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