|
8 | 8 | It is strongly suggested you complete the recommended readings for weeks 1-7 |
9 | 9 | *before* attempting this lab/workshop. |
10 | 10 |
|
11 | | -## A. Code review |
| 11 | +## 1. Code review |
12 | 12 |
|
13 | 13 | *Code review* is careful, systematic study of source code by people who are not |
14 | 14 | the original author of the code. It's analogous to having someone proofread |
@@ -46,7 +46,7 @@ to code review. |
46 | 46 |
|
47 | 47 | [code-review-stack]: https://codereview.stackexchange.com |
48 | 48 |
|
49 | | -## B. Exercise |
| 49 | +## 2. Exercise |
50 | 50 |
|
51 | 51 |
|
52 | 52 | <!-- |
@@ -308,7 +308,7 @@ probably aren't necessary (but Javadoc documentation still is). |
308 | 308 |
|
309 | 309 |
|
310 | 310 |
|
311 | | -## C. Linters and formatters |
| 311 | +## 3. Linters and formatters |
312 | 312 |
|
313 | 313 | In general, it's expensive to spend the time of humans doing |
314 | 314 | something a computer could do equally well -- like formatting code |
@@ -350,120 +350,9 @@ problems they can flag. |
350 | 350 |
|
351 | 351 | \newpage |
352 | 352 |
|
353 | | -## D. Ant build files and code coverage tools |
354 | 353 |
|
355 | | -This exercise is to get you familiar with code coverage tools and some of their weaknesses. |
356 | 354 |
|
357 | | -A repository with Java code is provided at |
358 | | -<https://github.com/cits5501/week-8-lab-coverage-example> which contains a simple class |
359 | | -for detecting whether a Java string is a palindrome (`Palindrome.java`), and tests for |
360 | | -this class using JUnit. |
361 | | - |
362 | | -You can use [GitPod](https://www.gitpod.io) to work with this code online. You will need a GitHub account; once you |
363 | | -have one set up, follow the link below: |
364 | | - |
365 | | - <https://gitpod.io/new/#https://github.com/cits5501/week-8-lab-coverage-example> |
366 | | - |
367 | | -and select "New workspace". |
368 | | - |
369 | | -After a minute or two, you should get access to an online version of the VS Code editor in which |
370 | | -the source code for the repository is available. Take a look at the `build.xml` file; this file |
371 | | -is used by the [Apache Ant][ant] build automation tool. It defines |
372 | | -several "targets" representing tasks that can be run using the build |
373 | | -file: |
374 | | - |
375 | | -[ant]: https://en.wikipedia.org/wiki/Apache_Ant |
376 | | - |
377 | | -- init |
378 | | -- compile |
379 | | -- compileTest |
380 | | -- test, and |
381 | | -- report. |
382 | | - |
383 | | -(Some of these tasks you can also do just using VS Code. For instance, |
384 | | -open `PalindromeTest.java`, expand the "outline" and "java projects" |
385 | | -panes, and wait for the background tasks to finish. |
386 | | -A green triangle should appear next to the start of the `PalindromeTest` |
387 | | -class, indicating that it can be clicked to run the JUnit tests it |
388 | | -contains.) |
389 | | - |
390 | | -Click the "Terminal" pane, and type `ant test` to run the JUnit tests. |
391 | | -The messages should indicate that four tests were run with no failures. |
392 | | - |
393 | | -Now run `ant report`, and not only will the tests be run, but the paths |
394 | | -they take through the code of `PalindromeTest` will be recorded by a |
395 | | -tool called [JaCoCo][jacoco], and a report produced. |
396 | | - |
397 | | -[jacoco]: https://www.jacoco.org/jacoco/ |
398 | | - |
399 | | -You can view this by clicking "Go Live" in the VS Code taskbar (towards |
400 | | -the right). This serves up the contents of the repository directory via |
401 | | -HTTP, so it can be viewed in the browser. Click "report", and by |
402 | | -clicking through, you should be able to see a coverage report for our |
403 | | -tests. |
404 | | - |
405 | | - |
406 | | -{ width="20cm" } |
407 | | - |
408 | | - |
409 | | -Read the JaCoco documentation on "Coverage Counters", [here][cov], |
410 | | -for more information about exactly what is being measured. |
411 | | - |
412 | | -[cov]: https://www.eclemma.org/jacoco/trunk/doc/counters.html |
413 | | - |
414 | | -**Exercises** |
415 | | - |
416 | | -- Comment out one of the assert statements (e.g. the one containing |
417 | | - `p.isPalindrome("redivider")`) and replace it with the bare call to |
418 | | - `p.isPalindrome()`. |
419 | | - |
420 | | - Does the coverage report change at all? Try doing the same for all |
421 | | - tests, and check again. What weakness of coverage tools does this |
422 | | - suggest? |
423 | | - |
424 | | -- Comment out all but one of the tests. Again, does the coverage report |
425 | | - change? |
426 | | - |
427 | | -- Applying the ideas from ISP (but without necessarily doing a detailed |
428 | | - analysis) -- can you spot any test cases that are missing from the |
429 | | - test suite? |
430 | | - |
431 | | - |
432 | | -<div class="solutions"> |
433 | | - |
434 | | -\solbox |
435 | | - |
436 | | -**Solution** |
437 | | - |
438 | | -The coverage report doesn't change in any of the above |
439 | | -cases. |
440 | | -
|
441 | | -This suggests we could have a very weak test suite, consisting |
442 | | -of just one test case -- say, an empty string (`""`) -- and with no |
443 | | -assertions, and full coverage would still be reported. |
444 | | -
|
445 | | -If changes are made to the code, we could easily introduce errors that |
446 | | -aren't picked up by the test suite. |
447 | | - |
448 | | -When we look at mutation testing, we will see ways of assessing the |
449 | | -quality of our tests which do not depend on measuring coverage as |
450 | | -reported by tools like JaCoCo. |
451 | | - |
452 | | -As for a missing test case: an empty string (a degenerate or "border" |
453 | | -case) would be a good thing to test for, as would single-letter strings, |
454 | | -but this is not done. |
455 | | - |
456 | | - |
457 | | -</div> |
458 | | -\endsolbox |
459 | | - |
460 | | - |
461 | | -\newpage |
462 | | - |
463 | | - |
464 | | - |
465 | | - |
466 | | -## E. Summary |
| 355 | +## 4. Summary |
467 | 356 |
|
468 | 357 | Code review is a widely-used technique for improving software quality by |
469 | 358 | human inspection. Code review can detect many kinds of problems in code, |
|
0 commit comments