unit tests and automated testing

21
Unit Tests & Automated Testing Lee Englestone presents.. www.manchesterdeveloper .com

Upload: lee-englestone

Post on 22-Nov-2014

5.525 views

Category:

Technology


2 download

DESCRIPTION

A short presentation on Unit Tests and Automated Testing

TRANSCRIPT

Page 1: Unit Tests And Automated Testing

Unit Tests & Automated Testing

Lee Englestone presents..

www.manchesterdeveloper.com

Page 2: Unit Tests And Automated Testing

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)

Page 3: Unit Tests And Automated Testing

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

Page 4: Unit Tests And Automated Testing

Why should we TEST?

Why should we test at all?£

£

£

££

££

REMEMBER

Testing is just one

step in QA

Page 5: Unit Tests And Automated Testing

Testing different layers

Business Logic

Unit Tests

Web UISelenium

Page 6: Unit Tests And Automated Testing

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

Page 7: Unit Tests And Automated Testing

Testing business logic

Business Logic (DLL)

Data Access Layer

Code libraries (DLLs)

Database access

Unit Tests (DLL)

Unit Tests (DLLs)

Page 8: Unit Tests And Automated Testing

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)

Page 9: Unit Tests And Automated Testing

Unit Testing is not a Silver Bullet

Page 10: Unit Tests And Automated Testing

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

Page 11: Unit Tests And Automated Testing

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

Page 12: Unit Tests And Automated Testing

Example unit test : Running

Running unit tests manually with NUnit

Page 13: Unit Tests And Automated Testing

An example scenario

{ Code Example }Objects

Car

PropertiesColor Colordouble Valuedouble FuelLeveldouble FuelCapacityFuelTypeEnum FuelType

MethodsCar.Crush()Car.Paint(Color)Car.AddFuel(FuelTypeEnum, double)Car.VeryImportantMethod()

Page 14: Unit Tests And Automated Testing

Automating unit testing

Page 15: Unit Tests And Automated 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 }

Page 16: Unit Tests And Automated Testing

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)

Page 17: Unit Tests And Automated Testing

Code coverage

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

TestedNot Tested

Page 18: Unit Tests And Automated Testing

Summary

Test as early as possible

Design code to test Separate BL from UI

Improve QA

Make unit tests part of CI

Page 19: Unit Tests And Automated Testing
Page 20: Unit Tests And Automated Testing

Appendixes

Wikipedia testing definitions

Page 21: Unit Tests And Automated Testing

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