1 / 39

CS115 Class 15: Testing

CS115 Class 15: Testing. Due today User Manual Software Inspections Review: Testing Next time Review No Silver Bullet. French Guyana, June 4, 1996. $800 million software failure. Mars Climate Orbiter.

ashtyn
Télécharger la présentation

CS115 Class 15: Testing

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. CS115 Class 15: Testing • Due today • User Manual • Software Inspections • Review: Testing • Next time • Review No Silver Bullet

  2. French Guyana, June 4, 1996 $800 million software failure

  3. Mars Climate Orbiter • The 125 million dollar Mars Climate Orbiter is assumed lost by officials at NASA. The failure responsible for loss of the orbiter is attributed to a failure of NASA’s system engineer process. The process did not specify the system of measurement to be used on the project. As a result, one of the development teams used Imperial measurement while the other used the metric system of measurement. When parameters from one module were passed to another during orbit navigation correct, no conversion was performed, resulting in the loss of the craft.

  4. More BSOD Embarrassments

  5. Economic Impact • NIST study • On CNN.com - April 27, 2003 http://www.nist.gov/director/prog-ofc/report02-3.pdf

  6. Basic Definitions • Error-mistake or deviation from correct value • Failure-unacceptable system behavior • Defect/fault-flaw in any part of system that may cause a failure

  7. Testing Objective • Find defects/faults • Find them effectively • as many as possible • Find them efficiently • as many as possible given testing time

  8. Testing scope • Unit • Integration • System • Acceptance • Alpha/Beta

  9. Test approach • White box • Black box

  10. Decision Maker Programmer Tester Software Development Today Why do we have this structure?

  11. Decision Maker Programmer Tester Typical Scenario (1) “OK, calm down. We’ll slip the schedule. Try again.” “It doesn’t #$%& compile!” “I’m done.”

  12. Decision Maker Programmer Tester Typical Scenario (2) “Now remember, we’re all in this together. Try again.” “It doesn’t install!” “I’m done.”

  13. Decision Maker Programmer Tester Typical Scenario (3) “Let’s have a meeting to straighten out the spec.” “It does the wrong thing in half the tests.” “I’m done.” “No, half of your tests are wrong!”

  14. Decision Maker Programmer Tester Typical Scenario (4) “Try again, but please hurry up!” “It still fails some tests we agreed on.” “I’m done.”

  15. Decision Maker Programmer Tester Typical Scenario (5) “Oops, the world has changed. Here’s the new spec.” “Yes, it’s done!” “I’m done.”

  16. Decision Maker Programmer Tester Software Development Today Why do we have this structure?

  17. Standard Testing Questions • How shall we generate/select test cases? • Did this test execution succeed or fail? • How do we know when to stop testing?

  18. Summary • Testing is hard • If done manually, also very expensive and boring • Use inspections! • Will save more time in testing and debugging • A number of techniques can make testing effective • Randomized testing • Exhaustive testing on small examples • Regression testing with nightly build

  19. Back to Design • Testing has a profound impact on design • Because some designs are easier to test • Design software so it can be tested!

  20. Principles of Testability • Avoid unpredictable results • No unnecessary non-deterministic behavior • Design in self-checking • At appropriate places have system check its own work • Asserts • May require adding some redundancy to the code • Have a test interface • Minimize interactions between features • Number of interactions can easily grow huge • Rich breeding ground for bugs

  21. JUnit Test automation

  22. Benefits of JUnit • Free - http://www.junit.org • Automatic check of expected vs. actual • Simple to use – quick to write and run • Tests are written in Java

  23. Design of JUnit • Built around Command pattern • each method under test is represented by a separate test method

  24. JUnit Sample Unit Test write tests for all methods in a class import junit.framework.TestCase public class ShoppingCartTest extends TestCase { protected void setUp() {…} protected void tearDown() {…} public void testEmpty() {…} public void testAddItem() {…} }

  25. How to create a test suite import junit.framework.TestSuite; public class EcommerceTestSuite { public static Test suite() { TestSuite suite = new TestSuite(); suite.addTestSuite(ShoppingCartTest.class); suite.addTest(CreditCardTestSuite.suite()); } /** * Runs the test suite using the textual runner. */ public static void main(String[] args) { junit.textui.TestRunner.run(suite()); } }

  26. A GUI for running the test suite java junit.swingui.TestRunner EcommerceTestSuite

  27. Initialization called before every test case method protected void setUp() { cart = new ShoppingCart(); book1 = new Product("Pragmatic Unit Testing", 29.95); cart.addItem(book1); }

  28. Clean up called after every test case method protected void tearDown() { // set to null any references to big objects

  29. Tests the empty method public void testEmpty() { cart.empty(); assertEquals(0, cart.getItemCount()); }

  30. Tests addItem method public void testAddItem() { Product book2 = new Product("Pragmatic Project Automation", 29.95); cart.addItem(book2); double expectedBalance = book1.getPrice() + book2.getPrice(); assertEquals(expectedBalance, cart.getBalance()); assertEquals(2, cart.getItemCount()); }

  31. Output of JUnit >java junit.textui.TestRunner TestServer 1) testAddItem AssertionFailedError: expected:<59.90> but was:<59.00 >

  32. JUnit assertXXX • assertEquals(x,y) // .equals, or values • assertFalse(boolean expr) • assertNotNull(obj ref) • assertNotSame(x, y) // using == • assertNull() • assertSame() • assertTrue() • fail() public void testPassNullsToConstructor(){ try{ Server s = new Server(null, null); fail(“Expected IllegalArgumentException”); } catch (IllegalArgumentException expected){} }

  33. JUnit Sequence • New test case for every test<foo> method • For each test<foo> method • create new object • no sharing of instance variables between tests • setUp() • test<foo> • tearDown()

  34. JUnit Practices • One function check per test method • usually one assert per test • sometimes more • failure aborts entire method • Many test<foo> per TestCase • Can group multiple TestCase into a TestSuite

  35. JUnit Recommendations • Add JUnit tests in your code • run regularly (eg before SVN commit) • Benefits: • catch errors early • easier to debug, easier to fix • reduce cost of integration testing • reduce risk • of large, untested code base • of late slips in schedule (no time to recover) • increase confidence, reduce stress

  36. More details ... • JUnit home: www.junit.org • Tutorial http://clarkware.com/articles/JUnitPrimer.html • Also (thanks Stan) • http://www.soe.ucsc.edu/classes/cmps115/Spring06/SECURE/9904c.htm

  37. “Best Practices” Session • By now, you have now developed some expertise in your particular specialization • (tester, coder, documenter, facilitator) • Group by specialization to discuss • what knowledge you’ve gained • what works, what doesn’t • tips to help other teams • Short (5min) presentation using doc camera

More Related