29
Testing Steve Loughran HP Laboratories June 9th, 2008

Testing

Embed Size (px)

DESCRIPTION

Talk for undergraduates on why they should embrace testing

Citation preview

Page 1: Testing

Testing

Steve LoughranHP LaboratoriesJune 9th, 2008

Page 2: Testing

About me* I break things for a

living* this is because I am

clumsy* breaking other people’s

code is fun* sometimes it is really

hard

Page 3: Testing

Ant in Action* the problems of complex

builds in big teams* not for this course* stay in the IDE* testing is key to getting

big projects out the door* automation comes next

Page 4: Testing

your code doesn't work

Page 5: Testing

I know this because...

Page 6: Testing

my code doesn't work

Page 7: Testing

it's OK to write code that doesn’t work

Page 8: Testing

but not to ship it

Page 9: Testing

especially when it matters

Page 10: Testing

how do you get from "broken" to "shipping"?

Page 11: Testing

Device Drivers

ship and see

test it!

Test-Driven

x: y : f(y, x)>0

Formal Methods

prove it works

Page 12: Testing

proofs of correctness

+shows an algorithm really works+good for concurrency+and other things you can’t test

- makes assumptions about system- needs lots of maths/CS skills

(Pi-Calculus, The HOL System)- how do you do regression proofs?

Page 13: Testing

Testing: code that breaks

* unit test: test classes, libraries* functional test: test the application* system test: test a deployed system* performance test: simulate load.* acceptance tests: is it ready for use?

a good test breaks the build!

Page 14: Testing

Test Driven Development

any feature without a test doesn’t exist

Page 15: Testing

Lots of unit test frameworks

* Java: JUnit, TestNG* Python: PyUnit* Ruby: Test::Unit * .NET: NUnit* PHP: PHPUnit* C++ (CppUnit)

Page 16: Testing

JUnit

* main unit test framework in Java (see also TestNG)

* simple to learn* good tool support* somewhat low-level* extensions for system testing

Page 17: Testing

+count Test Cases( )+r un( )

«i nt er f ace»Test

+asser t Tr ue( )+asser t Fal se( )+f ai l ( )+asser t Equal s( )+asser t Same( )+asser t Not Same( )+asser t Nul l ( )+asser t Not Nul l ( )

Assert

+set Up( )+t earDown( )

TestCaseTestSui te

1

*

Page 18: Testing

public class LessSimpleTest extends TestCase {

public LessSimpleTest(String s) { super(s); }

public void testAssignment() { final Date date = new Date(); Event event = new Event(UUID.randomUUID(),

date, "now", "Text"); assertEquals("self equality failed", event, event); assertEquals(date, event.getDate()); assertNotNull(date.getID()); }}

Page 19: Testing

swing GUI TestRunner

Page 20: Testing

Ant-generated report

scales better; reports published

Page 21: Testing

Continuous Integration

see: CruiseControl, Hudson, LuntBuild

Page 22: Testing

==> blame assignment

whose change broke the build?

Page 23: Testing

System Testing

* deploy, then:HtmlUnit, XmlUnit, Cactus, Selenium

* needs automated deployment, database setup, teardown

* performance testing by comparing timings w.r.t. old runs

* simulate entire behaviour of the client user/application

Page 24: Testing

Distributed Systems

testing is still a research topic

* set up complex configurations* run tests on remote machines* collect results and log data* post-mortem analysis* virtualization can help

see http://tinyurl.com/y99tez

Page 25: Testing

limitations of testing

- good tests are hard to write- distributed tests very hard- different system configurations are still a

problem- status of "tester" below "coder"

A good test breaks the application

Page 26: Testing

politics:resistance to change

Page 27: Testing

developers: ignorance, fear

E.E.E. Educate, Evangelise, Encourage

* gently show benefits* use testing to track down a bug* retain test for regression testing* add tests for new code and old problems, not

existing codebase* adopt cruise control, reporting

Page 28: Testing

management: ignorance

"too much time spent on testing"

* out of date with modern processes* belief that testing slows the schedule (it does

on the ship-and-see process)

E.E.E., then D.D.D: Distract, Dissemble, Defeat

Page 29: Testing

call to action

* write tests* use a CI tool: Hudson,

Luntbuild,Cruise Control