Beatiful tests

15
Beautiful Tests Tests that are beautiful for their simplicity Monday, October 21, 13

description

Code is typically considered beautiful if it does what it's supposed to do with unique elegance and economic. Tests can also be beautiful themselves. More importantly, they can play a key role in helping you create more beautiful code. From Nguyen Hoang Viet - Asskicker at Silicon Straits Saigon

Transcript of Beatiful tests

Page 1: Beatiful tests

Beautiful TestsTests that are beautiful for their simplicity

Monday, October 21, 13

Page 2: Beatiful tests

Binary Search

Monday, October 21, 13

Page 3: Beatiful tests

The bug:

int mid = (low + high) / 2;

Solution:

int mid = low + ((high - low) / 2);

Show off:

int mid = (low + high) >>> 1;

Monday, October 21, 13

Page 4: Beatiful tests

My initial testing strategy

Start with smoke tests.

Add some boundary value tests

Continue with various thorough and exhaustive types of tests

Finally, add some performance tests

Monday, October 21, 13

Page 5: Beatiful tests

Smoking Allowed (and Encouraged)

These are designed to make sure that the code does the right thing when used in the most basic manner

Monday, October 21, 13

Page 6: Beatiful tests

Smoking Allowed (and Encouraged)

“confidence maintenance”

Monday, October 21, 13

Page 7: Beatiful tests

Pushing the Boundaries

Boundary testing is designed to explore and validate what happens when the code has to deal with extremes and corner cases

Monday, October 21, 13

Page 8: Beatiful tests

Pushing the Boundaries

very large array ????

Monday, October 21, 13

Page 9: Beatiful tests

Pushing the Boundaries

Monday, October 21, 13

Page 10: Beatiful tests

Pushing the Boundaries

Monday, October 21, 13

Page 11: Beatiful tests

Random Acts of Testing

A way to generate a large and diverse set of inputs

A set of generalized assertions that will work on any input

Monday, October 21, 13

Page 12: Beatiful tests

Random Acts of Testing

Monday, October 21, 13

Page 13: Beatiful tests

Performance Anxiety

Monday, October 21, 13

Page 14: Beatiful tests

ConclusionUnit Tests allows you to make big changes to code quickly

Your tests give you confidence that you've done enough for now and can stop tweaking and move on to the next thing

Good unit tests can help document and define what something is supposed to do

Unit Tests help you really understand the design of the code you are working on

Monday, October 21, 13

Page 15: Beatiful tests

Monday, October 21, 13