16
#DevoxxUS @spoole167 @stuartmarks TEN SIMPLE RULES FOR WRITING GREAT TESTCASES

Ten Simple Rules for Writing Great Testcases

Embed Size (px)

Citation preview

Page 1: Ten Simple Rules for Writing Great Testcases

#DevoxxUS @spoole167 @stuartmarks

TEN SIMPLE RULES FOR WRITING GREAT TESTCASES

Page 2: Ten Simple Rules for Writing Great Testcases

#DevoxxUS @spoole167 @stuartmarks

Steve Poole : IBM

JVM Developer

DevOps practitioner

Developer Advocate

Stuart Marks : Oracle

Principal MTS

Java / OpenJDK Core Libraries

Page 3: Ten Simple Rules for Writing Great Testcases

#DevoxxUS @spoole167 @stuartmarks

“I get paid for code that works, not for tests”

How to maximize your effort and protect your investment in tests and testing now with

addedCloud

Page 4: Ten Simple Rules for Writing Great Testcases

#DevoxxUS @spoole167 @stuartmarks

1. Think before you act2. Make your tests understandable3. Keep your tests “small and simple”4. Test one thing only5. Fast tests only6. Absolute repeatability7. Independent tests only8. Provide diagnostic data on failure 9. No hard-coding of your environment10.No extraneous output

Page 5: Ten Simple Rules for Writing Great Testcases

#DevoxxUS @spoole167 @stuartmarks

1. Think before you act

What are you testing?

Why are you testing?

Planht

tps:

//ww

w.fl

ickr

.com

/pho

tos/

ayur

vedi

cmed

icin

es/

Page 6: Ten Simple Rules for Writing Great Testcases

#DevoxxUS @spoole167 @stuartmarks

2. Make your tests understandable

Comments

Expected behaviour

Aid debug

Diagnostics

http

s://w

ww

.flic

kr.c

om/p

hoto

s/83

6334

10@

N07

/

Page 7: Ten Simple Rules for Writing Great Testcases

#DevoxxUS @spoole167 @stuartmarks

3. Keep your tests “small and simple”

Separate test logic / setup

Much easier to debug

Use setup / teardown

https://www.flickr.com/photos/9266144@N02/

Page 8: Ten Simple Rules for Writing Great Testcases

#DevoxxUS @spoole167 @stuartmarks

4. Test one thing only

One scenario per test

Enables fast debug

Obvious why test failed

https://www.flickr.com/photos/ryantron/

Page 9: Ten Simple Rules for Writing Great Testcases

#DevoxxUS @spoole167 @stuartmarks

5. Fast tests only

Run unit tests often as possible

Maintain quality bar

Quick results

https://www.flickr.com/photos/mcleod/

Page 10: Ten Simple Rules for Writing Great Testcases

#DevoxxUS @spoole167 @stuartmarks

6. Absolute repeatability

Non-deterministictests are a headache

Fix intermittent tests immediately

No value, waste of resource

Must trust all tests

https://www.flickr.com/photos/fdecomite/

Page 11: Ten Simple Rules for Writing Great Testcases

#DevoxxUS @spoole167 @stuartmarks

7. Independent tests only

Must run in any order

Run subset, faster results

No dependencies

http

s://w

ww

.flic

kr.c

om/p

hoto

s/sh

eila

_sun

d/

Page 12: Ten Simple Rules for Writing Great Testcases

#DevoxxUS @spoole167 @stuartmarks

8. Provide diagnostic data on failure

Use message in asserts

Make it simple to debug

Reference input dataRecord test environment info ht

tps:

//ww

w.fl

ickr

.com

/pho

tos/

davi

dbak

er/

Page 13: Ten Simple Rules for Writing Great Testcases

#DevoxxUS @spoole167 @stuartmarks

9. No hard-coding of your environment

No ports, IP addresses,data files, databases

Use config files, systemproperties or mock objects

Portable tests

http

s://w

ww

.flic

kr.c

om/p

hoto

s/pu

g50/

Page 14: Ten Simple Rules for Writing Great Testcases

#DevoxxUS @spoole167 @stuartmarks

10. No extraneous output

A passing test is a silent test

Too much output = confusion

Use option, config file toturn on debug, save output

http

s://w

ww

.flic

kr.c

om/p

hoto

s/3-

bs/

Page 15: Ten Simple Rules for Writing Great Testcases

#DevoxxUS @spoole167 @stuartmarks

Pirate rules

Guidelines only

Some may seen obvious.

Some may seem pedantic

Until you inherit a testsuite…

Thank you.https://www.flickr.com/photos/gapic/

Page 16: Ten Simple Rules for Writing Great Testcases

© 2017 IBM Corporation

Mission Badge #6:SMS Text

Your mission should you choose to accept it….

Join us at the IBM Booth for hands-on labs, demos, games and talk to our developers.

Text Mission2017 to 41411to get the booth giveaway and learn more about all the IBM sessions & speakers.

Enter the raffle by completing missions for a chance to win• a Drone• TJBot Kit • VR glasses