how i learned to stop worrying love the bug project
play

How I Learned to Stop Worrying & Love the Bug Project Management - PowerPoint PPT Presentation

Picture Courtesy of: Dr. Sarah Ford How I Learned to Stop Worrying & Love the Bug Project Management Clarification Your project manager is in charge of your project They are your manager You write the user stories for your project


  1. Picture Courtesy of: Dr. Sarah Ford How I Learned to Stop Worrying & Love the Bug

  2. Project Management Clarification ¨ Your project manager is in charge of your project ¤ They are your manager ¨ You write the user stories for your project ¤ Your PM will choose which stories you will complete each sprint ¤ Your PM will decide which tasks are assigned to whom ¨ Not all PMs will manage projects the same way ¤ This is expected ¤ They are given some amount of freedom to decide the best approach for a particular team ¤ All projects are different and will require different approaches

  3. Announcements ¨ Course focused on software engineering concepts ¤ “Make cool stuff” nice, but already know capable of this ¤ Trying to develop experience & skills on important topics ¤ Rubric (& scores) reflect emphasis; efforts should follow ¨ Even for 1 st sprint, project grows around user stories ¤ Write many more stories than sprint will complete ¤ Improve grade by checking stories written correctly ¤ Create & use tasks to complete work for each sprint ¤ Task & acceptance tests yield “perfect” product

  4. Terminology ¨ "Acceptance tests" check user story complete ¤ Ensures feature works and ready for deployment ¤ Run by client as part of release demo ¤ Ensure full understanding of all aspects of feature ¨ "Task tests" check that a task is complete ¤ Ensures task complete and ready for inclusion ¤ Run by developers in preparation for daily stand-up ¤ Finds bugs during coding & through later changes ¤ Also defines what success like to enable parallel work

  5. Secret of Good Code

  6. Secret of Good Code

  7. Good Code Works

  8. Write Code For Testing ¨ Quality of product decided by testing ¤ Testability critical design concern , for code to work

  9. Test-Driven Development (TDD) ¨ Very popular technique developing software

  10. Tests We Usually Write

  11. Tests We Should Write

  12. Tests We Should Write

  13. Tests We Should Write

  14. Test-Driven Development (TDD) ¨ Traditional coding practices changed from the start ¨ Write tests BEFORE begin implementation process Write stubs (but no code) for class & methods 1. Knowing correct outputs, write tests to check 2. Implement methods to pass your tests (& check often) 3.

  15. Common Objection To TDD But… How could I write tests before I know what the method does?

  16. Smart Programmer Responds… How could you write the code before you know what the method must do?

  17. TDD Objections ¨ Feels weird to start with tests when you first try… ¨ .. but objections reflect poor habits checking code ¤ Know method’s outcomes when starting to write… ¤ … but you may not know how it will be done

  18. TDD Key Concept Check method’s results NOT method’s processes

  19. Why TDD Helps ¨ Many benefits when test cases created first ¤ Clarify what method does so coding becomes easier ¤ Since written for tests, methods become easier to fix ¤ Know when code done by checking if tests pass ¨ Studies have found that TDD simplifies debugging ¤ Know when bug created by running tests regularly ¤ Tests start to fail after writing 1 line: bug on that line ¤ Bugs… somewhere(?) when hours pass before testing

  20. Unit Testing Library ¨ Most languages have x Unit library for unit testing ¤ Tests written in language so can run anywhere ¤ Strong support that makes writing tests very easy ¤ Supported by most IDEs (e.g., Eclipse, IntelliJ, BlueJ) ¤ Started with Java – JUnit still gold standard for testing ¨ Automation important to allow frequent testing ¤ Testing easy – just select “Run As…” “JUnit test” ¤ Green means good – checking results also very easy ¤ Easy to see problems – see red when tests fail

  21. JUnit Test Cases Format ¨ Most often write test class for each class ¤ Identical to other classes; usually named ____Test ¤ As regular class, can use inheritance & have fields ¤ Inheritance & fields not required like any Java class ¨ Since ver. 4.0, JUnit’s annotations identify tests ¤ Extra information added to show method is test case ¤ Annotation added immediately before method

  22. JUnit Annotations ¨ Loop until all test cases in class are executed ¤ JUnit executes all methods marked @Before n Optional methods initialize any data before each test ¤ Run exactly 1 method labeled @Test executed ¤ Executes all methods marked @After n Also optional, cleans mess made by @Before

  23. Statements Performing Checks assertEquals ( X expected, X actual) assertEquals ( float exp, float act, float tol) assertEquals ( double exp, double act, double tol) assertTrue ( boolean test) assertFalse ( boolean test) assertNull ( Object objTest) assertNotNull ( Object objTest) fail ()

  24. Statements Performing Checks assertEquals ( X expected, X actual) @Test method assertEquals ( float exp, float act, float tol) should result in assertEquals ( double exp, double act, double tol) calling 1 or more assertTrue ( boolean test) assert* statement. assertFalse ( boolean test) Assertion must not hold assertNull ( Object objTest) for method to fail. assertNotNull ( Object objTest) fail ()

  25. Writing Test Methods ¨ Test methods MUST have @Test annotation ¤ Non- static , void methods only for JUnit to work ¤ By same logic, test methods cannot have parameters ¨ Uses normal code to write these test methods ¤ Just normal methods; can contain any legal Java code ¤ Conditionals and loop statements occasionally included ¤ Can instantiate objects and call methods on objects ¤ Other methods can use assert___ & be called by tests

  26. assertEquals With Decimals ¨ Computers actually very bad at math:

  27. assertEquals With Decimals ¨ Computers actually very bad at math:

  28. Math Checks With Decimals ¨ Computers actually very bad at math ¤ Decimal numbers hard & imprecision always created ¤ Not limited to computers: can you write 2 / 3 as decimal?

  29. Math Checks With Decimals ¨ Computers actually very bad at math ¤ Decimal numbers hard & imprecision always created ¤ Not limited to computers: can you write 2 / 3 as decimal? ¨ Must specify tolerance for decimal comparisons ¤ float or double equal if difference below tolerance assertEquals ( float expect, float act, float tolerance) assertEquals ( double expect, double act, double tolerance)

  30. Tests Key Concept #1 Include tolerance (allowed rounding error) for floating point arithmetic checks

  31. Math Checks With Decimals ¨ Examples of this in use: float act = 0.2; assertEquals(0.3, act, 0.01); assertEquals(10.1, act, 10.00); ¨ Tolerance depends on problem & precision needed ¤ If unclear, just pick reasonable value (Dr. Hertz uses 0.001)

  32. Test Method Outline Declare variable(s), create objects, & prep inputs 1. Call the method being tested 2. Use specification to verify returned value correct 3. Check fields for changes matching requirements 4. Can also verify other fields did not change 5. Assert array & object arguments also correct 6.

  33. Class To Be Tested public class Operational { private int a, b; public Operational(int fst, int snd) { a = fst; b = snd; } public String multiply() { int product = a * b; return “Product is ”+product; } public String sum() { return “Sum is ”+a+b; } }

  34. Class To Be Tested public class Operational { private int a, b; public Operational(int fst, int snd) { a = fst; b = snd; } public String multiply() { int product = a * b; return “Product is ”+product; } This concatenates a & b public String sum() { return “Sum is ”+a+b; (like Strings) rather than } adding them. So 3 + 2 will } be 32 and not 5. Our tests need to find this!

  35. Starting Test Cases ¨ Traditionally, test class adds “Test” to class name ¤ Each case is method having @Test annotation public class OperationalTest { @Test public void testMult0() { Operational xByZero = new Operational(3, 0); Operational zeroByX = new Operational(0, 17); assertEquals(“Product is 0”, xByZero.multiply()); assertEquals(“Product is 0”, zeroByX.multiply()); }

  36. Starting Test Cases ¨ Traditionally, test class adds “Test” to class name ¤ Each case is method having @Test annotation public class OperationalTest { @Test public void testMult0() { Operational xByZero = new Operational(3, 0); Operational zeroByX = new Operational(0, 17); assertEquals(“Product is 0”, xByZero.multiply()); assertEquals(“Product is 0”, zeroByX.multiply()); }

  37. Starting Test Cases ¨ Traditionally, test class adds “Test” to class name ¤ Each case is method having @Test annotation public class OperationalTest { @Test public void testMult0() { Operational xByZero = new Operational(3, 0); Operational zeroByX = new Operational(0, 17); assertEquals(“Product is 0”, xByZero.multiply()); assertEquals(“Product is 0”, zeroByX.multiply()); }

  38. Bad Tests to Write ¨ Only get to know test failed with assertTrue() @Test public void yuckyButLegal() { Operational xByOne = new Operational(-2, 1); assertTrue(xByOne.multiply() .equals(“Product is 2”)); }

  39. Bad Tests to Write ¨ Only get to know test failed with assertTrue() @Test public void yuckyButLegal() { Operational xByOne = new Operational(-2, 1); assertTrue(xByOne.multiply() .equals(“Product is 2”)); }

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend