Unit Tests & Automated TestingLee Englestone presents..www.manchesterdeveloper.com
AgendaTerminologyWhat, Why, HowAutomating unit tests & testingAdvanced stuffTest driven development (TDD)Code coverageWhat we wont be coveringContinuous Integration (in any depth)
Terminology (for the next hour)Unit testTests a small bit of code (from code)Integration testTest after addition of codeSystem test / functional testTest for adherence to user requirements Regression testTest that fixing / adding code hasn’t introduced bugsContinuous integrationAutomated checkout, building and testing of code from source controlSource : Lee & Wikipedia
Why should we TEST?Why should we test at all?££REMEMBERTesting is just one step in QA£££££
Testing different layersBusiness LogicUnit TestsWeb UISelenium
Three tier architectureWeb UIASPX, ASCX, HTML, Flash,EpiServer Page Templates etcBusiness LogicCode libraries (DLLs)Business Logic (DLL)Database accessData Access Layer
Testing business logicCode libraries (DLLs)Business Logic (DLL)Unit Tests (DLL)Unit Tests (DLLs)Database accessData Access Layer
Why have unit tests?Why have unit tests?Find bugs early / fast feedbackIncrease QAWhy not to have unit testsIncreases development time?CostOfWritingUnitTests < Sum(BugFixing)
Unit Testing is not a Silver Bullet
What is a unit test?“..tests if individual units of source code are fit for use.”Should beSmallSpecific (only test 1 thing)Clear pass / fail criteria
What does a unit test look like? Using NUnit.Framework;[TestFixture]public class CarTests{	[Test]	public void Test_Car_Paint ()	{	// ArrangeColor paint = Color.Red;	Car car = new Car();	// Actcar.paint(Color.Red);	// AssertAssert.AreEqual(car.Color, paint);	}	…}ArrangeActAssert
Example unit test : RunningRunning unit tests manually with NUnit
An example scenario{ Code Example }ObjectsCarPropertiesColorColordouble Valuedouble FuelLeveldouble FuelCapacityFuelTypeEnumFuelTypeMethodsCar.Crush()Car.Paint(Color)Car.AddFuel(FuelTypeEnum, double)Car.VeryImportantMethod()
Automating unit testing
Testing Web UI (Selenium)What if we want to test the UI? Manual recording and runningCan export to NUnitExamples : Community Fund FormH1 checking**{ Code Example }
Test driven development (TDD)Write your tests, even BEFORE your code!Make sure all tests initially failThen implement the code that the tests are testing(Encourages Designing for Testing)
Code coverageWhat % of your code base are you testing?
Summary	Test as early as possibleDesign code to testSeparate BL from UIImprove QAMake unit tests part of CI
AppendixesWikipedia testing definitions
Testing Terminology (Wikipedia)Unit test“..a programmer tests if individual units of source code are fit for use.”Integration test“..individual software modules are combined and tested as a group. It occurs after unit testing and before system testing.”System test / functional test“..testing conducted on a complete, integrated system to evaluate the system's compliance with its specified requirements. Regression test“..seeks to uncover software errors by partially retesting a modified program. The intent of regression testing is to assure that a bug fix has been successfully corrected .. , while providing a general assurance that no other errors were introduced in the process of fixing the original problem.”Continuous integrationAutomated checkout, building and testing of code from source controlSource : Wikipedia

Unit Tests And Automated Testing

  • 1.
    Unit Tests &Automated TestingLee Englestone presents..www.manchesterdeveloper.com
  • 2.
    AgendaTerminologyWhat, Why, HowAutomatingunit tests & testingAdvanced stuffTest driven development (TDD)Code coverageWhat we wont be coveringContinuous Integration (in any depth)
  • 3.
    Terminology (for thenext hour)Unit testTests a small bit of code (from code)Integration testTest after addition of codeSystem test / functional testTest for adherence to user requirements Regression testTest that fixing / adding code hasn’t introduced bugsContinuous integrationAutomated checkout, building and testing of code from source controlSource : Lee & Wikipedia
  • 4.
    Why should weTEST?Why should we test at all?££REMEMBERTesting is just one step in QA£££££
  • 5.
    Testing different layersBusinessLogicUnit TestsWeb UISelenium
  • 6.
    Three tier architectureWebUIASPX, ASCX, HTML, Flash,EpiServer Page Templates etcBusiness LogicCode libraries (DLLs)Business Logic (DLL)Database accessData Access Layer
  • 7.
    Testing business logicCodelibraries (DLLs)Business Logic (DLL)Unit Tests (DLL)Unit Tests (DLLs)Database accessData Access Layer
  • 8.
    Why have unittests?Why have unit tests?Find bugs early / fast feedbackIncrease QAWhy not to have unit testsIncreases development time?CostOfWritingUnitTests < Sum(BugFixing)
  • 9.
    Unit Testing isnot a Silver Bullet
  • 10.
    What is aunit test?“..tests if individual units of source code are fit for use.”Should beSmallSpecific (only test 1 thing)Clear pass / fail criteria
  • 11.
    What does aunit test look like? Using NUnit.Framework;[TestFixture]public class CarTests{ [Test] public void Test_Car_Paint () { // ArrangeColor paint = Color.Red; Car car = new Car(); // Actcar.paint(Color.Red); // AssertAssert.AreEqual(car.Color, paint); } …}ArrangeActAssert
  • 12.
    Example unit test: RunningRunning unit tests manually with NUnit
  • 13.
    An example scenario{Code Example }ObjectsCarPropertiesColorColordouble Valuedouble FuelLeveldouble FuelCapacityFuelTypeEnumFuelTypeMethodsCar.Crush()Car.Paint(Color)Car.AddFuel(FuelTypeEnum, double)Car.VeryImportantMethod()
  • 14.
  • 15.
    Testing Web UI(Selenium)What if we want to test the UI? Manual recording and runningCan export to NUnitExamples : Community Fund FormH1 checking**{ Code Example }
  • 16.
    Test driven development(TDD)Write your tests, even BEFORE your code!Make sure all tests initially failThen implement the code that the tests are testing(Encourages Designing for Testing)
  • 17.
    Code coverageWhat %of your code base are you testing?
  • 18.
    Summary Test as earlyas possibleDesign code to testSeparate BL from UIImprove QAMake unit tests part of CI
  • 20.
  • 21.
    Testing Terminology (Wikipedia)Unittest“..a programmer tests if individual units of source code are fit for use.”Integration test“..individual software modules are combined and tested as a group. It occurs after unit testing and before system testing.”System test / functional test“..testing conducted on a complete, integrated system to evaluate the system's compliance with its specified requirements. Regression test“..seeks to uncover software errors by partially retesting a modified program. The intent of regression testing is to assure that a bug fix has been successfully corrected .. , while providing a general assurance that no other errors were introduced in the process of fixing the original problem.”Continuous integrationAutomated checkout, building and testing of code from source controlSource : Wikipedia

Editor's Notes

  • #10 There are no silver bullets in development.Developers have are there disposal an arsenal tools, and they must be used in the right way to fit company processes