Unit Test in a nutshell 
Short presentation of a method to verify isolated units of code 
agile42 | We advise, train and coach companies building software | www.agile42.com | Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License
About me 
Roberto Bettazzoni 
Agile Coach 
eXtreme Programming Trainer 
! 
Certified Scrum Professional 
>30 years of coding (and still proudly counting) 
! 
roberto.bettazzoni@agile42.com 
linkedin.com/in/robertobettazzoni 
@bettazzoni 
agile42 | We advise, train and coach companies building software | www.agile42.com | Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License
unit test 
Method to verify isolated units of code 
agile42 | We advise, train and coach companies building software | www.agile42.com | Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License
unit test 
user 
code 
Acceptance Criteria test 
Functional test 
Unit test 
Unit tests are written 
by coders for coders 
to test the code design 
agile42 | We advise, train and coach companies building software | www.agile42.com | Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License
unit test 
Method to verify isolated units of code 
agile42 | We advise, train and coach companies building software | www.agile42.com | Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License
unit test 
Method to verify isolated units of code 
agile42 | We advise, train and coach companies building software | www.agile42.com | Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License
unit test 
assert( condition ) 
agile42 | We advise, train and coach companies building software | www.agile42.com | Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License
unit test library 
assert( bool condition ) 
assertEqual( <T> a, <T> b ) 
assertEqual( float a, float b, float precision) 
assertThrow( exceptionType, function) 
agile42 | We advise, train and coach companies building software | www.agile42.com | Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License
unit test 
Method to verify isolated units of code 
agile42 | We advise, train and coach companies building software | www.agile42.com | Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License
Test Isolation 
A 
B 
C 
D 
agile42 | We advise, train and coach companies building software | www.agile42.com | Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License
Test Isolation 
Run 4 tests: A, B, C, D 
A 
B 
C 
D 
agile42 | We advise, train and coach companies building software | www.agile42.com | Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License
Test Isolation 
A 
B 
C 
D 
agile42 | We advise, train and coach companies building software | www.agile42.com | Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License
Test Isolation 
Run 3 tests: A, B, D 
A 
B 
D 
agile42 | We advise, train and coach companies building software | www.agile42.com | Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License
Test Isolation 
Run 3 tests: D, A, B 
D 
A 
B 
agile42 | We advise, train and coach companies building software | www.agile42.com | Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License
unit test library 
test() 
agile42 | We advise, train and coach companies building software | www.agile42.com | Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License
unit test library 
setup() - test() - teardown() 
agile42 | We advise, train and coach companies building software | www.agile42.com | Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License
unit test library 
Test Class also known as TestCase or TestFixture 
{ 
setup() {} 
teardown() {} 
! 
test_method_1() 
test_method_2() 
test_method_3() 
} 
agile42 | We advise, train and coach companies building software | www.agile42.com | Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License
unit test library 
Test Class also known as TestCase or TestFixture 
setup() - test_method_1() - teardown() 
setup() - test_method_2() - teardown() 
setup() - test_method_3() - teardown() 
agile42 | We advise, train and coach companies building software | www.agile42.com | Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License
unit test 
Method to verify isolated units of code 
agile42 | We advise, train and coach companies building software | www.agile42.com | Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License
unit test - What is a unit of code? 
Classes 
Methods 
Functions 
Blocks of code 
agile42 | We advise, train and coach companies building software | www.agile42.com | Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License
Code Isolation (or Unit Isolation) 
A 
B 
C 
D 
agile42 | We advise, train and coach companies building software | www.agile42.com | Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License
Code Isolation (or Unit Isolation) 
A 
B 
C 
D 
agile42 | We advise, train and coach companies building software | www.agile42.com | Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License
Take a guess 
What makes a “good unit test”? 
agile42 | We advise, train and coach companies building software | www.agile42.com | Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License
Take a guess 
What makes a “good unit test”? 
Readability 
agile42 | We advise, train and coach companies building software | www.agile42.com | Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License
Food for thoughts 
agile42 | We advise, train and coach companies building software | www.agile42.com | Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License

Unit test in a nutshell

  • 1.
    Unit Test ina nutshell Short presentation of a method to verify isolated units of code agile42 | We advise, train and coach companies building software | www.agile42.com | Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License
  • 2.
    About me RobertoBettazzoni Agile Coach eXtreme Programming Trainer ! Certified Scrum Professional >30 years of coding (and still proudly counting) ! roberto.bettazzoni@agile42.com linkedin.com/in/robertobettazzoni @bettazzoni agile42 | We advise, train and coach companies building software | www.agile42.com | Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License
  • 3.
    unit test Methodto verify isolated units of code agile42 | We advise, train and coach companies building software | www.agile42.com | Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License
  • 4.
    unit test user code Acceptance Criteria test Functional test Unit test Unit tests are written by coders for coders to test the code design agile42 | We advise, train and coach companies building software | www.agile42.com | Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License
  • 5.
    unit test Methodto verify isolated units of code agile42 | We advise, train and coach companies building software | www.agile42.com | Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License
  • 6.
    unit test Methodto verify isolated units of code agile42 | We advise, train and coach companies building software | www.agile42.com | Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License
  • 7.
    unit test assert(condition ) agile42 | We advise, train and coach companies building software | www.agile42.com | Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License
  • 8.
    unit test library assert( bool condition ) assertEqual( <T> a, <T> b ) assertEqual( float a, float b, float precision) assertThrow( exceptionType, function) agile42 | We advise, train and coach companies building software | www.agile42.com | Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License
  • 9.
    unit test Methodto verify isolated units of code agile42 | We advise, train and coach companies building software | www.agile42.com | Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License
  • 10.
    Test Isolation A B C D agile42 | We advise, train and coach companies building software | www.agile42.com | Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License
  • 11.
    Test Isolation Run4 tests: A, B, C, D A B C D agile42 | We advise, train and coach companies building software | www.agile42.com | Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License
  • 12.
    Test Isolation A B C D agile42 | We advise, train and coach companies building software | www.agile42.com | Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License
  • 13.
    Test Isolation Run3 tests: A, B, D A B D agile42 | We advise, train and coach companies building software | www.agile42.com | Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License
  • 14.
    Test Isolation Run3 tests: D, A, B D A B agile42 | We advise, train and coach companies building software | www.agile42.com | Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License
  • 15.
    unit test library test() agile42 | We advise, train and coach companies building software | www.agile42.com | Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License
  • 16.
    unit test library setup() - test() - teardown() agile42 | We advise, train and coach companies building software | www.agile42.com | Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License
  • 17.
    unit test library Test Class also known as TestCase or TestFixture { setup() {} teardown() {} ! test_method_1() test_method_2() test_method_3() } agile42 | We advise, train and coach companies building software | www.agile42.com | Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License
  • 18.
    unit test library Test Class also known as TestCase or TestFixture setup() - test_method_1() - teardown() setup() - test_method_2() - teardown() setup() - test_method_3() - teardown() agile42 | We advise, train and coach companies building software | www.agile42.com | Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License
  • 19.
    unit test Methodto verify isolated units of code agile42 | We advise, train and coach companies building software | www.agile42.com | Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License
  • 20.
    unit test -What is a unit of code? Classes Methods Functions Blocks of code agile42 | We advise, train and coach companies building software | www.agile42.com | Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License
  • 21.
    Code Isolation (orUnit Isolation) A B C D agile42 | We advise, train and coach companies building software | www.agile42.com | Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License
  • 22.
    Code Isolation (orUnit Isolation) A B C D agile42 | We advise, train and coach companies building software | www.agile42.com | Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License
  • 23.
    Take a guess What makes a “good unit test”? agile42 | We advise, train and coach companies building software | www.agile42.com | Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License
  • 24.
    Take a guess What makes a “good unit test”? Readability agile42 | We advise, train and coach companies building software | www.agile42.com | Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License
  • 25.
    Food for thoughts agile42 | We advise, train and coach companies building software | www.agile42.com | Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License