Unit Tests And Automated Testing

Preview:

DESCRIPTION

A short presentation on Unit Tests and Automated Testing

Citation preview

Unit Tests & Automated Testing

Lee Englestone presents..

www.manchesterdeveloper.com

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)

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 hasn’t introduced bugs

Continuous integration Automated checkout, building and testing of code from source control

Source : Lee & Wikipedia

Why should we TEST?

Why should we test at all?£

£

£

££

££

REMEMBER

Testing is just one

step in QA

Testing different layers

Business Logic

Unit Tests

Web UISelenium

Three tier architecture

Web UI

Business Logic (DLL)

Data Access Layer

ASPX, ASCX, HTML, Flash,EpiServer Page Templates etc

Code libraries (DLLs)

Database access

Business Logic

Testing business logic

Business Logic (DLL)

Data Access Layer

Code libraries (DLLs)

Database access

Unit Tests (DLL)

Unit Tests (DLLs)

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)

Unit Testing is not a Silver Bullet

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

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);

}…

}

ArrangeAct

Assert

Example unit test : Running

Running unit tests manually with NUnit

An example scenario

{ Code Example }Objects

Car

PropertiesColor Colordouble Valuedouble FuelLeveldouble FuelCapacityFuelTypeEnum FuelType

MethodsCar.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 running

Can export to NUnit

Examples : Community Fund Form H1 checking**{ Code Example }

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)

Code coverage

What % of your code base are you testing? % of code base tested

TestedNot Tested

Summary

Test as early as possible

Design code to test Separate BL from UI

Improve QA

Make unit tests part of CI

Appendixes

Wikipedia 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 integration Automated checkout, building and testing of code from source control

Source : Wikipedia

Recommended