Examination hints

Figure 609. Personal examination cheat sheets Slide presentation

Figure 610. Unit tests in examinations Slide presentation
  • Task definitions by Javadoc.

  • Corresponding Unit tests.

  • Automated evaluation scoring your achievements.

  • Individual weights reflecting a test's significance.


Figure 611. Example interface definition Slide presentation
/**
* Finde das n-te ungerade Element einer Wertefolge.
* 
* <p>Beispiel: Im Array {3, 2, 0, 1, 4} ist der Wert «1» an der Index-
*   position «3» das zweite ungerade Element.</p>
* 
* @param werte Die zu durchsuchenden Werte.
* @param n Die gewünschte Position, Start bei 1.
* 
* @return Den Index des n-ten ungeraden Wertes falls es mindestens n
* ungerade Werte gibt, ...
*/
static public int getNtesUngeradesElement(final int[] werte, final int n){     
    return 12345; // TODO: Implementiere mich korrekt!
}

Figure 612. Corresponding test Slide presentation
@Test
@Marking(points=1) /* 1 point if test passes */
public void test_400() {
  Assert.assertEquals(
    2, /* Expected result */
    Helper.getNtesUngeradesElement(new int[]{-4,  6,  1, -2,   8}, 1));
}

Figure 613. Don't cheat! Slide presentation
Unit Tests Your solution
assertFalse(isPrime(1));
assertTrue (isPrime(2));
assertTrue (isPrime(3));
assertFalse(isPrime(4));
assertTrue (isPrime(5));
assertFalse(isPrime(6));
assertTrue (isPrime(7));
assertFalse(isPrime(8));
assertFalse(isPrime(9));
assertFalse(isPrime(10));
... boolean isPrime(final int p) {
  switch (p) {
    case 2:
    case 3:
    case 5:
    case 7:
      return true;
    default:
      return false;    }

Will be treated as an attempt at deception / Täuschungsversuch.


Figure 614. Unit tests strategy in examinations Slide presentation
  • Unit testing is relentless: You are no longer at high school where a result having just a wrong sign used to matter next to nothing.

  • Focus on completing units of work rather than nearly finishing a large number of tasks.

  • Watching a test fail just happens. Learn to systematically fix bugs:

    1. Use your IDE's debugger. Practise debugging Junit tests individually addressing failures one by one.

    2. Insert log statements using log4j.