quo pertentas, oss?

45
Quo pertentas, OSS? How Open Source can benefit from well-crafted Tests Björn Kimminich Web: http://kimminich.de Twitter: @bkimminich v1.0

Upload: bjoern-kimminich

Post on 07-Dec-2014

1.036 views

Category:

Technology


0 download

DESCRIPTION

Quo pertentas, OSS? - How Open Source can benefit from well-crafted Tests This talk illustrates how a suite of well-written tests can benefit any Open Source project on multiple levels*: - improve maintainability of the code-base - help increase the truck factor** of the project - "after-the-fact" tests help understand existing code and serve as documentation - Behavior Driven Development (BDD) concepts can help create specification-like tests The idea of adding BDD-style unit tests was introduced into the actively developed OWASP ZAP project end of 2012. It will be explained - how the ZAP team approached this task initially - what the improvements for the project were so far - where we are going with automated testing in the future Disclaimer: Some source code will definetely be shown during this talk, but you won't need to be a Java expert to follow the story! Having some general programming experience is totally sufficient! *= surprisingly also works for proprietary software projects! **= number of contributors that could be (fatally) run over by a truck without effectively killing the project

TRANSCRIPT

Page 1: Quo pertentas, OSS?

Quo pertentas, OSS?How Open Source can benefit from well-crafted Tests

Björn KimminichWeb: http://kimminich.de

Twitter: @bkimminichv1.0

Page 2: Quo pertentas, OSS?

Let‘s start with some code…

Page 3: Quo pertentas, OSS?

…and a corresponding unit test!

Page 4: Quo pertentas, OSS?

It passes with flying colors…

Page 5: Quo pertentas, OSS?

… and achieves 100% codecoverage!

Page 6: Quo pertentas, OSS?

Nothing could possibly go wrong!

Page 7: Quo pertentas, OSS?

How about adding another test?

Page 8: Quo pertentas, OSS?

Oops!

Page 9: Quo pertentas, OSS?

Finding Bugs in Open Source Software

Page 10: Quo pertentas, OSS?

Code Reviews

Cartoon: Geek & Poke

Pair

Pro

gra

mm

ing

Infeasiblewith remote development

OccasionallyduringHackathons

Peer

Revie

w

Developers review eachother

Hard toorganizeproperly

Co

mm

itte

rR

evie

w

Not everyonehas commitrights

Senior developersreviewcontributionsbefore mergeinto master

Page 11: Quo pertentas, OSS?

Static Code Analysis

Cartoon: Geek & Poke

Some commercial Tools might be more powerful…

…but are typically not affordable for OSS projects

Find code smells and potential programming errors…

…but miss a lot as well …or produce false positives

Popular Open Source Tools

FindBugs CheckStyle PMD Sonar

Page 12: Quo pertentas, OSS?

Testing

Test Types

Unit Tests

Integration Tests

GUI Tests

Manual Tests

Load/Stress Tests

Penetration Tests

Cartoon: Geek & Poke

Page 13: Quo pertentas, OSS?

Best vs. Bad Practices for Testing

Page 16: Quo pertentas, OSS?

Happy Path Testing

Photo: Tortured Mind Photography

Page 17: Quo pertentas, OSS?

Testing Border & Exceptional Cases

Page 18: Quo pertentas, OSS?

No Assertions

Page 19: Quo pertentas, OSS?

API Tests

Page 20: Quo pertentas, OSS?

Scenario Tests with BDD

Page 21: Quo pertentas, OSS?

Benefits of well-crafted Tests for OSS

Page 22: Quo pertentas, OSS?

Maintainability++

A suite of automated regression tests helps finding defects resulting from code changes

New contributors do not have to fear touching old code…

…neither do long-time committers after a longer vacation!

Cartoon: Geek & Poke

Page 23: Quo pertentas, OSS?

Documentation++

External and Javadoc documentation tends to rot quickly and becomes obsolete or even misleading

Tests that get outdated tend to break, so they have to be fixed resulting in updated documentation

Well-written tests document the intended behavior of a class or component

Even if the production code is hard to understand, a good test can help to fill this gap

Cartoon: Geek & Poke

Page 24: Quo pertentas, OSS?

Specification++

Writing tests before the production code is even better than just documenting existing code

Consequent TDD / BDD will let the Tests become the actual specification of the program's intended behavior

Failing tests indicate that the specification is not met yet (or any more)

Cartoon: Geek & Poke

Page 25: Quo pertentas, OSS?

Contribution++

Well maintained, documented and tested projects are safer and more fun to contribute to

Nobody likes working on an untested piece of unreadable code (especially in their free time)

Cartoon: Geek & Poke

Page 26: Quo pertentas, OSS?

Truck Factor++

How many project contributors could be fatally hit by a truck before the project perishes?

The lower the number, the more volatile the project as it relies on individual experts

The number can be increased by spreading knowledge and lowering entry barriers

Cartoon: Geek & Poke

Page 27: Quo pertentas, OSS?

Introducing Unit Tests to OWASP ZAP

Page 28: Quo pertentas, OSS?

OWASP Zed Attack Proxy (ZAP)

Easy-to-useintegratedpenetration-testing tool

Locates vulnerabilities in web applications

Helps building secure apps

OWASP Flagship Project

Programmed in Java with javax.swing UI

Page 29: Quo pertentas, OSS?

How to contribute to ZAP?

Develop core features https://code.google.com/p/zaproxy/

Develop addons https://code.google.com/p/zap-extensions/

Help with translation https://crowdin.net/project/owasp-zap

Promote ZAP https://code.google.com/p/zaproxy/wiki/ZapEvangelists

Page 31: Quo pertentas, OSS?

Starting from zero Unit Tests

No Unit Tests

SomeJUnit-based

Integration tests

Page 32: Quo pertentas, OSS?

Separate Test Project

Page 33: Quo pertentas, OSS?

ZAPs first Unit Test

Page 34: Quo pertentas, OSS?

Adding some more Show Cases

Page 35: Quo pertentas, OSS?

Separation into Test Suites

Page 36: Quo pertentas, OSS?

Providing Test Guidelines

Types of Tests

Test Suites

Test Libraries

Naming Conventions

Behavior Driven Development

Code Quality

Code Coverage

Page 38: Quo pertentas, OSS?

Measure Code Coverage

Page 39: Quo pertentas, OSS?

Move Tests close to Production Code

Page 40: Quo pertentas, OSS?

Instant execution from IDE

Page 41: Quo pertentas, OSS?

Run all Tests during ContinuousBuild...

Page 42: Quo pertentas, OSS?

...and let it fail when any tests fail!

Page 43: Quo pertentas, OSS?

Future: Adding a GUI Testing Framework

ZAP is very UI heavy which makes a lot of the code hard orimpossible to unit test

Right now there are no GUI Tests in place for ZAP

Several free UI Testing Frameworks exist for Java Swing…

…unfortunately none is actively maintained any more

Page 44: Quo pertentas, OSS?

ConclusionTesting is a crucial part of Software Development

Good Tests are the better

documentation

Tests can make a differencebetween a prospering and a dead-endOSS project

Page 45: Quo pertentas, OSS?

Thank you!Björn Kimminich

Web: http://kimminich.de

Twitter: @bkimminich

Background Image: Eikira