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 best practices
Unit testing best practicesUnit testing best practices
Unit testing best practices
nickokiss
 
UNIT TESTING PPT
UNIT TESTING PPTUNIT TESTING PPT
UNIT TESTING PPT
suhasreddy1
 
Test Driven Development
Test Driven DevelopmentTest Driven Development
Test Driven Development
Dhaval Dalal
 

What's hot (20)

Workshop unit test
Workshop   unit testWorkshop   unit test
Workshop unit test
 
Unit testing with JUnit
Unit testing with JUnitUnit testing with JUnit
Unit testing with JUnit
 
Unit Testing
Unit TestingUnit Testing
Unit Testing
 
Test Driven Development
Test Driven DevelopmentTest Driven Development
Test Driven Development
 
Performance Testing
Performance TestingPerformance Testing
Performance Testing
 
Unit testing best practices
Unit testing best practicesUnit testing best practices
Unit testing best practices
 
Angular Unit Testing
Angular Unit TestingAngular Unit Testing
Angular Unit Testing
 
Junit
JunitJunit
Junit
 
Understanding Unit Testing
Understanding Unit TestingUnderstanding Unit Testing
Understanding Unit Testing
 
The Art of Unit Testing - Towards a Testable Design
The Art of Unit Testing - Towards a Testable DesignThe Art of Unit Testing - Towards a Testable Design
The Art of Unit Testing - Towards a Testable Design
 
Unit Testing in Angular
Unit Testing in AngularUnit Testing in Angular
Unit Testing in Angular
 
Unit Testing with Python
Unit Testing with PythonUnit Testing with Python
Unit Testing with Python
 
JUnit Presentation
JUnit PresentationJUnit Presentation
JUnit Presentation
 
Unit & integration testing
Unit & integration testingUnit & integration testing
Unit & integration testing
 
Python unit testing
Python unit testingPython unit testing
Python unit testing
 
Apache JMeter - A brief introduction
Apache JMeter - A brief introductionApache JMeter - A brief introduction
Apache JMeter - A brief introduction
 
JUnit 5
JUnit 5JUnit 5
JUnit 5
 
Writing Test Cases 20110808
Writing Test Cases 20110808Writing Test Cases 20110808
Writing Test Cases 20110808
 
UNIT TESTING PPT
UNIT TESTING PPTUNIT TESTING PPT
UNIT TESTING PPT
 
Test Driven Development
Test Driven DevelopmentTest Driven Development
Test Driven Development
 

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