Top Banner
Einstein building a minesweeper robot using tests Alister Scott ThoughtWorks Australia
29

Einstein - Australia and New Zealand Testing Board · a web implementation of ... automatically controlled automated unit tests using RSpec w/ mocks automated functional tests using

Jul 28, 2018

Download

Documents

ngoliem
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Einstein - Australia and New Zealand Testing Board · a web implementation of ... automatically controlled automated unit tests using RSpec w/ mocks automated functional tests using

Einsteinbuilding a minesweeper robot using tests

Alister ScottThoughtWorks Australia

Page 2: Einstein - Australia and New Zealand Testing Board · a web implementation of ... automatically controlled automated unit tests using RSpec w/ mocks automated functional tests using

Mini skirt presentation

Page 3: Einstein - Australia and New Zealand Testing Board · a web implementation of ... automatically controlled automated unit tests using RSpec w/ mocks automated functional tests using

minesweeper.github.com

pure CoffeeScript

347 lines of CoffeeScript =>

478 lines of JavaScript

Page 4: Einstein - Australia and New Zealand Testing Board · a web implementation of ... automatically controlled automated unit tests using RSpec w/ mocks automated functional tests using

minesweeper.github.comJasmine specs

74 specs in 0.3 seconds

687 lines of CoffeeScript

(nearly double prod code)

Page 5: Einstein - Australia and New Zealand Testing Board · a web implementation of ... automatically controlled automated unit tests using RSpec w/ mocks automated functional tests using

how do we create an Einstein robot?

tests!

how?

Page 6: Einstein - Australia and New Zealand Testing Board · a web implementation of ... automatically controlled automated unit tests using RSpec w/ mocks automated functional tests using

outsidein

Page 7: Einstein - Australia and New Zealand Testing Board · a web implementation of ... automatically controlled automated unit tests using RSpec w/ mocks automated functional tests using

"Are you facing an issue that's too big to wrap your mind around? Break it down. Keep dividing problems into smaller and smaller pieces until you're able to digest them."

~ Getting Real - 37Signals

[http://gettingreal.37signals.com/ch06_Shrink_Your_Time.php]

Break it down

Page 8: Einstein - Australia and New Zealand Testing Board · a web implementation of ... automatically controlled automated unit tests using RSpec w/ mocks automated functional tests using

stage one: guess

Page 9: Einstein - Australia and New Zealand Testing Board · a web implementation of ... automatically controlled automated unit tests using RSpec w/ mocks automated functional tests using

success rate: < 0.1%

Page 10: Einstein - Australia and New Zealand Testing Board · a web implementation of ... automatically controlled automated unit tests using RSpec w/ mocks automated functional tests using

stage two: identify obvious mines

Page 11: Einstein - Australia and New Zealand Testing Board · a web implementation of ... automatically controlled automated unit tests using RSpec w/ mocks automated functional tests using

stage two: identify obvious mines

Page 12: Einstein - Australia and New Zealand Testing Board · a web implementation of ... automatically controlled automated unit tests using RSpec w/ mocks automated functional tests using

success rate:< 2%

Page 13: Einstein - Australia and New Zealand Testing Board · a web implementation of ... automatically controlled automated unit tests using RSpec w/ mocks automated functional tests using

stage three: guess better

Page 14: Einstein - Australia and New Zealand Testing Board · a web implementation of ... automatically controlled automated unit tests using RSpec w/ mocks automated functional tests using

success rate: 5%

Page 15: Einstein - Australia and New Zealand Testing Board · a web implementation of ... automatically controlled automated unit tests using RSpec w/ mocks automated functional tests using

stage four: 'clusters'

Page 16: Einstein - Australia and New Zealand Testing Board · a web implementation of ... automatically controlled automated unit tests using RSpec w/ mocks automated functional tests using

success rate: 13%

Page 17: Einstein - Australia and New Zealand Testing Board · a web implementation of ... automatically controlled automated unit tests using RSpec w/ mocks automated functional tests using

stage five:'derived clusters'

success rate: 20%

Page 18: Einstein - Australia and New Zealand Testing Board · a web implementation of ... automatically controlled automated unit tests using RSpec w/ mocks automated functional tests using

progressive intelligence: law of diminishing returns?

detect some safe cells

detect some obvious mines

clustersguessing by field probability

derived clusters

related clusters

Page 19: Einstein - Australia and New Zealand Testing Board · a web implementation of ... automatically controlled automated unit tests using RSpec w/ mocks automated functional tests using

a minesweeper robot:separation of concerns

can play any minesweeper implementation game using in

built intelligence

a web implementation of minesweeper that can be automatically controlled

automated unit tests using RSpec w/ mocks

automated functional tests using Cucumber & Watir-

Webdriver

Page 20: Einstein - Australia and New Zealand Testing Board · a web implementation of ... automatically controlled automated unit tests using RSpec w/ mocks automated functional tests using

minesweeper robot testing pyramid

automated unit tests using RSpec w/ mocks

automated functional tests using Cucumber &

Watir-Webdriver

48 specs in 0.2 seconds

1 feature: 4 scenarios35 seconds

Page 21: Einstein - Australia and New Zealand Testing Board · a web implementation of ... automatically controlled automated unit tests using RSpec w/ mocks automated functional tests using

exploratory testing

automated unit tests using RSpec w/ mocks

?manual exploratory testing:scan logs

look at screenshots on guesses

automated functional tests using Cucumber &

Watir-Webdriver

Page 22: Einstein - Australia and New Zealand Testing Board · a web implementation of ... automatically controlled automated unit tests using RSpec w/ mocks automated functional tests using

eliminate unnecessary guesses!

● Let robot play heaps of games ● Study each guess (screenshot)● Was it absolutely necessary to guess? If

not, it's a bug!● Write failing spec from screenshot● Then make it pass!

Exploratory Testing

Page 23: Einstein - Australia and New Zealand Testing Board · a web implementation of ... automatically controlled automated unit tests using RSpec w/ mocks automated functional tests using

example: gets hard

describe 'safe cells to click' doit 'should detect safe cells taking multiple non-adjacent cell clusters into consideration' do

analyse <<-EOF 3 * 3 1 2 1 * * 4 * 3 * 3 4 . . . 2 * 2 . 2 . 1 EOF analyser.safe_cells_to_click.should == [[3, 2],

[3, 4], [2, 3]]end

end

Page 24: Einstein - Australia and New Zealand Testing Board · a web implementation of ... automatically controlled automated unit tests using RSpec w/ mocks automated functional tests using

Performance TestingHow do you test performance of an algorithm that tries to solve a non-deterministic problem?

After thousands of runs, I found an expert mine field that can be solved without guessing (if you start by clicking 0,0)

Page 25: Einstein - Australia and New Zealand Testing Board · a web implementation of ... automatically controlled automated unit tests using RSpec w/ mocks automated functional tests using

Can always win this without guessing (start at 0,0)

Page 26: Einstein - Australia and New Zealand Testing Board · a web implementation of ... automatically controlled automated unit tests using RSpec w/ mocks automated functional tests using

Ensure we never degrade performance

Page 27: Einstein - Australia and New Zealand Testing Board · a web implementation of ... automatically controlled automated unit tests using RSpec w/ mocks automated functional tests using

Einstein'sPerformance MetricsBeginner

Games won: 85%Best time: 2 seconds

Intermediate:Games won: 65%Best time: 8 seconds

Expert:Games won: 20%Best time: 21 seconds

Page 28: Einstein - Australia and New Zealand Testing Board · a web implementation of ... automatically controlled automated unit tests using RSpec w/ mocks automated functional tests using

Enough talk alreadyLet's see Einstein in action!

[http://soundcloud.com/blaketothefuture/nyan-cat-the-movie]

Page 29: Einstein - Australia and New Zealand Testing Board · a web implementation of ... automatically controlled automated unit tests using RSpec w/ mocks automated functional tests using

Bonus time ~Lessons Learned● Break big things down into little things● Design for testability● Test in the right places ● Supplement your automated testing● Build in performance measures● Change your mind● Be young, be foolish, be happy