Unit testing

936 views
870 views

Published on

Everyone says you should test your designs, but expects you to know what that testing should be. Here we briefly look at the kinds of tests (software) engineers might encounter and what the terms being used actually mean. Finally we settle on Unit Testing as a good place to begin the testing process.

Published in: Technology
0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
936
On SlideShare
0
From Embeds
0
Number of Embeds
31
Actions
Shares
0
Downloads
6
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide
  • GOOD AFTERNOON MY NAME IS …
  • TESTING IS A LARGE TOPIC … LET’S LIMIT OURSELVES FOR THE SAKE OF THIS TALK TO SOMETHING MANAGEABLE
  • TESTING IS GENERALLY BROKEN INTO ONE OF 3 CATEGORIES, REFERRED TO AS “COLORS”
  • BEYOND WHAT WE”VE DISCUSSED SO FAR< THERE ARE MANY OTHER KINDS OF “TESTS” POSSIBLE
  • WHY USE THIS? (see references at end) I’M PRODUCTIVE AND COMFORTABLE AS IS. (… and your code is always bug free?)
  • OUR CODE WAS NOT BUILT TO BE SAVEABLE – WHAT DO I CHANGE … ?
  • NO DEFINITION – NO JavaDoc. NO ACCESS TO ALL ROUTINES. YOU COULD USE JAVA INTROSPECTION – WHATEVER HAPPENED TO K.I.S.S.?
  • WHAT ABOUT LEGACY CODE? HOW HARD TO UPGRADE?
  • THIS WAS JUST AN INTRODUCTION. THERE ARE SOME VERY USEFUL TOPICS WE HAVE NOT EVEN TOUCHED ON.
  • ‘NUF SAID!
  • Unit testing

    1. 1. Unit Testing Save yourself and your project Jeslie Chermak ( [email_address] )
    2. 2. What is “testing”? <ul><li>(We’re going to focus on software) </li></ul><ul><li>Testing is the process of validating that software meets its design goals, behaves as expected, and can be duplicated: http://en.wikipedia.org/wiki/Software_testing </li></ul><ul><li>Note: Most of what we’ll discuss applies equally to any other type of testing as well. </li></ul>
    3. 3. Testing “colors” <ul><li>There really are only three: </li></ul><ul><li>http://en.wikipedia.org/wiki/Software_testing - The_box_approach </li></ul><ul><li>Black box –based on no knowledge of the actual inner workings (e.g., using just the spec. or user’s guide). </li></ul><ul><li>White box – based on detailed knowledge of the actual implementation. </li></ul><ul><li>Gray box – everything in between black and white. </li></ul>
    4. 4. Testing “levels” <ul><li>Again, basically three levels: http://en.wikipedia.org/wiki/Software_testing - Testing_levels </li></ul><ul><li>System test – entire “product” behaves </li></ul><ul><li>Integration test – one piece interacts properly with another piece </li></ul><ul><li>Unit test – one piece behaves correctly in isolation </li></ul>
    5. 5. Testing Objectives <ul><li>Again, basically three levels: </li></ul><ul><li>Acceptance tests – confirm that things work acceptably </li></ul><ul><li>Regression tests – confirm that prior problems remain resolved </li></ul><ul><li>Functional tests – confirm that things behave as expected </li></ul>
    6. 6. Other Testing Goals <ul><li>Security tests </li></ul><ul><li>Performance tests </li></ul><ul><li>Stability tests </li></ul><ul><li>Load tests tests </li></ul><ul><li>Usability tests </li></ul><ul><li>I18N/L10N tests </li></ul><ul><li>Destructive tests </li></ul>
    7. 7. Where Should I Start? <ul><li>“ Begin at the beginning, …” </li></ul><ul><li>King, “Alice in Wonderland” </li></ul><ul><li>Are you building something new? </li></ul><ul><li>Are you extending something old? </li></ul><ul><li>“ Where ever you go, there you are” </li></ul><ul><li>Buckaroo Bonzai, “Buckaroo Bonzai” </li></ul><ul><li>In the beginning, you test basics: you build white box, functional, unit tests. </li></ul>
    8. 8. Basic Principles <ul><li>“ Testing can only show the presence of bugs, not their absence.” </li></ul><ul><li>E. W. Dijkstra </li></ul><ul><li>Agile methodologies integrate testing as requisite part of the methodology </li></ul><ul><li>KISS </li></ul>
    9. 9. Some Observations <ul><li>You can not test what you … </li></ul><ul><li>don’t have a definition for; </li></ul><ul><li>can not control; </li></ul><ul><li>can not measure; </li></ul><ul><li>can not access. </li></ul>
    10. 10. Is this correct? <ul><li>package com.jcc.training.generics; </li></ul><ul><li>import java.util.ArrayList; </li></ul><ul><li>import java.util.List; </li></ul><ul><li>public class Stack implements java.io.Serializable { // marker interface </li></ul><ul><li>private final List stack = new ArrayList(); </li></ul><ul><li>public void push( final Integer value) { </li></ul><ul><li>this . stack .add(value); // NULL allowed! </li></ul><ul><li>} </li></ul><ul><li>private Integer top() { </li></ul><ul><li>if ( this . stack .isEmpty()) throw new IllegalStateException(); </li></ul><ul><li>return (Integer) this . stack .get( this . stack .size() - 1); </li></ul><ul><li>} </li></ul><ul><li>public Integer pop() { </li></ul><ul><li>final Integer value = this .top(); </li></ul><ul><li>this . stack .remove( this . stack .size() + 1); </li></ul><ul><li>return value; </li></ul><ul><li>} </li></ul><ul><li>} </li></ul>
    11. 11. More Observations <ul><li>Use a testing framework. </li></ul><ul><li>Make it a part of your IDE/process. </li></ul><ul><li>Test often, especially after a “trivial” change. </li></ul><ul><li>Make tests for old code before you change it. </li></ul>
    12. 12. Going Further … <ul><li>Wikipedia book: http://en.wikipedia.org/wiki/Book:Software_testing </li></ul><ul><li>Real world consequences: http://en.wikipedia.org/wiki/List_of_software_bugs </li></ul><ul><li>xUnit: http://en.wikipedia.org/wiki/XUnit </li></ul><ul><li>Google “software testing” </li></ul>
    13. 13. Closing thought … <ul><li>“ Beware of bugs in the above code; I have only proved it correct, not tried it.” </li></ul><ul><li>Donald Knuth </li></ul>

    ×