Test Driven Development
The 3 Fundamental Test Clauses

Fundamental Clauses

Fundamental Clauses: given

Fundamental Clauses: given

Example 1

@Test
public void testGetName() {
    // given
    Person person = new Person();
    String expectedName = "Leon";
    person.setName(expectedName);
}

Fundamental Clauses: given

Example 2

@Test
public void testGetItem() {
    // given
    Inventory inventory = new Inventory();
    String expectedItem = "Milk";
    inventory.add(expectedItem)
}

Fundamental Clauses: given

Example 3

Fundamental Clauses: when

Fundamental Clauses: when

Fundamental Clauses: when

Example 1

@Test
public void testGetName() {
    // given
    Person person = new Person();
    String expectedName = "Leon";
    person.setName(expectedName);

    // when
    String actualName = person.getName();
}

Fundamental Clauses: when

Example 2

@Test
public void testGetItem() {
    // given
    Inventory inventory = new Inventory();
    String expectedItem = "Milk";
    inventory.add(expectedItem)

    // when
    String expectedItem = inventory.get(0);
}

Fundamental Clauses: when

Example 3

@Test
public void testGetWinner() {
    // given
    Game game = new Game();
    Player expectedWinner = new Player();
    game.add(player);
    game.play();

    // when
    Player actualWinner = game.getWinner()
}

Fundamental Clauses: then

Fundamental Clauses: then

Example 1

@Test
public void testGetName() {
    // given
    Person person = new Person();
    String expectedName = "Leon";
    person.setName(expectedName);

    // when
    String actualName = person.getName();

    // then
    Assert.assertEquals(expectedName, actualName);
}

Fundamental Clauses: then

Example 2

@Test
public void testGetItem() {
    // given
    Inventory inventory = new Inventory();
    String expectedItem = "Milk";
    inventory.add(expectedItem)

    // when
    String actualItem = inventory.get(0);

    // then
    Assert.assertEquals(expectedItem, actualItem);
}

Fundamental Clauses: then

Example 3

@Test
public void testGetWinner() {
    // given
    Game game = new Game();
    Player expectedWinner = new Player();
    game.add(player);
    game.play();

    // when
    Player actualWinner = game.getWinner()

    // then
    Assert.assertEquals(expectedWinner, actualWinner)
}