Unit Tests And Automated Testing

Download Unit Tests And Automated Testing

Post on 22-Nov-2014

5.515 views

Category:

Technology

2 download

Embed Size (px)

DESCRIPTION

A short presentation on Unit Tests and Automated Testing

TRANSCRIPT

  • 1. Unit Tests & Automated Testing
    Lee Englestone presents..
    www.manchesterdeveloper.com
  • 2. Agenda
    Terminology
    What, Why, How
    Automating unit tests & testing
    Advanced stuff
    Test driven development (TDD)
    Code coverage
    What we wont be covering
    Continuous Integration (in any depth)
  • 3. Terminology (for the next hour)
    Unit test
    Tests a small bit of code (from code)
    Integration test
    Test after addition of code
    System test / functional test
    Test for adherence to user requirements
    Regression test
    Test that fixing / adding code hasnt introduced bugs
    Continuous integration
    Automated checkout, building and testing of code from source control
    Source : Lee & Wikipedia
  • 4. Why should we TEST?
    Why should we test at all?


    REMEMBER
    Testing is just one step in QA





  • 5. Testing different layers
    Business Logic
    Unit Tests
    Web UI
    Selenium
  • 6. Three tier architecture
    Web UI
    ASPX, ASCX, HTML, Flash,
    EpiServer Page Templates etc
    Business Logic
    Code libraries (DLLs)
    Business Logic (DLL)
    Database access
    Data Access Layer
  • 7. Testing business logic
    Code libraries (DLLs)
    Business Logic (DLL)
    Unit Tests (DLL)
    Unit Tests (DLLs)
    Database access
    Data Access Layer
  • 8. Why have unit tests?
    Why have unit tests?
    Find bugs early / fast feedback
    Increase QA
    Why not to have unit tests
    Increases development time?
    CostOfWritingUnitTests < Sum(BugFixing)
  • 9. Unit Testing
    is not a Silver Bullet
  • 10. What is a unit test?
    ..tests if individual units of source code are fit for use.
    Should be
    Small
    Specific (only test 1 thing)
    Clear pass / fail criteria
  • 11. What does a unit test look like?
    Using NUnit.Framework;
    [TestFixture]
    public class CarTests
    {
    [Test]
    public void Test_Car_Paint ()
    {
    // Arrange
    Color paint = Color.Red;
    Car car = new Car();
    // Act
    car.paint(Color.Red);
    // Assert
    Assert.AreEqual(car.Color, paint);
    }

    }
    Arrange
    Act
    Assert
  • 12. Example unit test : Running
    Running unit tests manually with NUnit
  • 13. An example scenario
    { Code Example }
    Objects
    Car
    Properties
    ColorColor
    double Value
    double FuelLevel
    double FuelCapacity
    FuelTypeEnumFuelType
    Methods
    Car.Crush()
    Car.Paint(Color)
    Car.AddFuel(FuelTypeEnum, double)
    Car.VeryImportantMethod()
  • 14. Automating unit testing
  • 15. Testing Web UI (Selenium)
    What if we want to test the UI?
    Manual recording and running
    Can export to NUnit
    Examples :
    Community Fund Form
    H1 checking**
    { Code Example }
  • 16. Test driven development (TDD)
    Write your tests, even BEFORE your code!
    Make sure all tests initially fail
    Then implement the code that the tests are testing
    (Encourages Designing for Testing)
  • 17. Code coverage
    What % of your code base are you testing?
  • 18. Summary
    Test as early as possible
    Design code to test
    Separate BL from UI
    Improve QA
    Make unit tests part of CI
  • 19.
  • 20. Appendixes
    Wikipedia testing definitions
  • 21. 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 integration
    Automated checkout, building and testing of code from source control
    Source : Wikipedia