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

how i learned to stop worrying love the bug project
SMART_READER_LITE
LIVE PREVIEW

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


slide-1
SLIDE 1

How I Learned to Stop Worrying & Love the Bug

Picture Courtesy of: Dr. Sarah Ford

slide-2
SLIDE 2

¨ 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

Project Management Clarification

slide-3
SLIDE 3

¨ 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 1st 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

Announcements

slide-4
SLIDE 4

¨ "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

Terminology

slide-5
SLIDE 5

Secret of Good Code

slide-6
SLIDE 6

Secret of Good Code

slide-7
SLIDE 7

Good Code Works

slide-8
SLIDE 8

¨ Quality of product decided by testing

¤ Testability critical design concern, for code to work

Write Code For Testing

slide-9
SLIDE 9

Test-Driven Development (TDD)

¨ Very popular technique developing software

slide-10
SLIDE 10

Tests We Usually Write

slide-11
SLIDE 11

Tests We Should Write

slide-12
SLIDE 12

Tests We Should Write

slide-13
SLIDE 13

Tests We Should Write

slide-14
SLIDE 14

¨ Traditional coding practices changed from the start ¨ Write tests BEFORE begin implementation process

1.

Write stubs (but no code) for class & methods

2.

Knowing correct outputs, write tests to check

3.

Implement methods to pass your tests (& check often)

Test-Driven Development (TDD)

slide-15
SLIDE 15

Common Objection To TDD

But…

How could I write tests before I know

what the

method does?

slide-16
SLIDE 16

Smart Programmer Responds… How could you write the code before you know

what the

method must do?

slide-17
SLIDE 17

¨ 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

TDD Objections

slide-18
SLIDE 18

TDD Key Concept

Check method’s results NOT method’s processes

slide-19
SLIDE 19

¨ 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

Why TDD Helps

slide-20
SLIDE 20

¨ Most languages have xUnit 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

Unit Testing Library

slide-21
SLIDE 21

¨ 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

JUnit Test Cases Format

slide-22
SLIDE 22

¨ 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

JUnit Annotations

slide-23
SLIDE 23

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()

Statements Performing Checks

slide-24
SLIDE 24

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()

Statements Performing Checks @Test method should result in calling 1 or more assert* statement. Assertion must not hold for method to fail.

slide-25
SLIDE 25

¨ 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

Writing Test Methods

slide-26
SLIDE 26

assertEquals With Decimals

¨ Computers actually very bad at math:

slide-27
SLIDE 27

assertEquals With Decimals

¨ Computers actually very bad at math:

slide-28
SLIDE 28

¨ Computers actually very bad at math

¤ Decimal numbers hard & imprecision always created ¤ Not limited to computers: can you write 2/3 as decimal?

Math Checks With Decimals

slide-29
SLIDE 29

¨ 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)

Math Checks With Decimals

slide-30
SLIDE 30

Tests Key Concept #1

Include tolerance

(allowed rounding error)

for

floating point arithmetic checks

slide-31
SLIDE 31

¨ 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)

Math Checks With Decimals

slide-32
SLIDE 32

Test Method Outline

1.

Declare variable(s), create objects, & prep inputs

2.

Call the method being tested

3.

Use specification to verify returned value correct

4.

Check fields for changes matching requirements

5.

Can also verify other fields did not change

6.

Assert array & object arguments also correct

slide-33
SLIDE 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; } }

slide-34
SLIDE 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; } public String sum() { return “Sum is ”+a+b; } }

This concatenates a & b (like Strings) rather than adding them. So 3 + 2 will be 32 and not 5. Our tests need to find this!

slide-35
SLIDE 35

¨ 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()); }

Starting Test Cases

slide-36
SLIDE 36

¨ 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()); }

Starting Test Cases

slide-37
SLIDE 37

¨ 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()); }

Starting Test Cases

slide-38
SLIDE 38

¨ 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”)); }

Bad Tests to Write

slide-39
SLIDE 39

¨ 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”)); }

Bad Tests to Write

slide-40
SLIDE 40

¨ Get more detailed results with assertEquals()

@Test public void muchImproved() { Operational xByOne = new Operational(-2, 1); assertEquals(“Product is 2”, xByOne.multiply()); }

Better Tests to Write

slide-41
SLIDE 41

¨ Get more detailed results with assertEquals()

@Test public void muchImproved() { Operational xByOne = new Operational(-2, 1); assertEquals(“Product is 2”, xByOne.multiply()); }

Better Tests to Write

slide-42
SLIDE 42

Tests Key Concept #2

Use assertTrue() & assertFalse()

  • nly for boolean

values & properties

slide-43
SLIDE 43

¨ Must be certain assert___ testing YOUR code

§

@Test public void whatAmITesting() { Operational xByOne = new Operational(-2, 1); assertEquals(“Product is -2”, “Product is ” + (-2 * 1)); }

More Test Gotchas

slide-44
SLIDE 44

¨ Must be certain assert___ testing YOUR code

§

@Test public void whatAmITesting() { Operational xByOne = new Operational(-2, 1); assertEquals(“Product is -2”, “Product is ” + (-2 * 1)); }

More Test Gotchas

slide-45
SLIDE 45

¨ Must be certain assert___ testing YOUR code

§

@Test public void whatAmITesting() { Operational xByOne = new Operational(-2, 1); assertEquals(“Product is -2”, “Product is ” + (-2 * 1)); }

More Test Gotchas

slide-46
SLIDE 46

Other Version of Gotcha

slide-47
SLIDE 47

Test Method Outline

1.

Declare variable(s), create objects, & prep inputs

  • 2. Call the method being tested

3.

Use specification to verify returned value correct

4.

Check fields for changes matching requirements

5.

Should also verify other fields did not change

6.

Assert array & object arguments also correct

slide-48
SLIDE 48

¨ Will this pass?

@Test public void passingIsNotFailing() { Operational xByOne = new Operational(-2, 1); xByOne.sum(); }

More Test Gotchas

slide-49
SLIDE 49

¨ Will this pass?

@Test public void passingIsNotFailing() { Operational xByOne = new Operational(-2, 1); xByOne.sum(); }

More Test Gotchas

slide-50
SLIDE 50

Tests Key Concept #3

Every @Test method

should execute

AT LEAST 1

assert_____()

slide-51
SLIDE 51

¨ Often make assumptions when writing code

¤ True writing code and still true writing test cases ¤ Passing ≠ correct; could be no tests were run ¤ May not check what you think; care needed writing tests

¨ Tests should be written & run before coding

¤ Tests must fail, since code has not yet been written!

¨ Before wasting time, always check assumptions

Assumptions Deadly

slide-52
SLIDE 52

Valid Issue; Invalid Objection

slide-53
SLIDE 53

¨ Hardcode assert___ expected value if it is possible

@Test public void shouldNotPassButDoesPass() { Operational xByOne = new Operational(-2, 1); assertEquals(“Sum is ” + -2 + 1, xByOne.sum()); }

Hardcode Your Checks

slide-54
SLIDE 54

¨ Hardcode assert___ expected value if it is possible

@Test public void shouldNotPassButDoesPass() { Operational xByOne = new Operational(-2, 1); assertEquals(“Sum is ” + -2 + 1, xByOne.sum()); }

Hardcode Your Checks

slide-55
SLIDE 55

¨ Hardcode assert___ expected value if it is possible

@Test public void nowFindsBug() { Operational xByOne = new Operational(-2, 1); assertEquals(“Sum is ” + -2 + 1, xByOne.sum()); assertEquals(“Sum is -1”, xByOne.sum()); }

Hardcode Your Checks

slide-56
SLIDE 56

Tests Key Concept #4

Make tests valuable

HARDCODING

EQUALS

KNOWING

slide-57
SLIDE 57

Evaluating Test Efforts

¨ Develop tests with detailed look at the algorithm ¨ Test coverage discussed often by people, but… ¨ … coverage can be measured many ways

Statement coverage Run each statement at least once Branch coverage Run each branch at least once Path coverage Run each possible branch combination at least once

Detail Increases

slide-58
SLIDE 58

Coverage Measures

1 2 3 5 4

All Statements: 1, 2, 3, 4, 5 All Branches: 1, 2, 3, 4, 5

1, 3, 5

All Paths: 1, 2, 3, 4, 5

1, 2, 3, 5 1, 3, 4, 5 1, 3, 5

slide-59
SLIDE 59

¨ Cannot prove there are no bugs

How To Write Tests

slide-60
SLIDE 60

¨ Cannot prove there are no bugs

How To Write Tests

Testing shows the presence, not the absence

  • f bugs
slide-61
SLIDE 61

¨ Cannot prove there are no bugs

¤ Can only show no bugs exist on those tests

How To Write Tests

Testing shows the presence, not the absence

  • f bugs
slide-62
SLIDE 62

¨ Start working on Sprint 1

¤ Break stories into tasks ¤ Remember the tests! Tests validate your understanding ¤ Coding can wait! Only prototype required for 1st sprint

For Next Lecture