Skip to the content.

Test Driven Development (TDD)

-

What is a unit test?

-

What is a unit test?

-

Example

// Given
String name = "Leon";
Integer age = 25;
Person leon = new Person(name, age);

// When
String getNameResult = leon.getName();
Integer getAgeResult = leon.getAge();

// Then
Assert.assertEquals(name, getNameResult);
Assert.assertEquals(age, getAgeResult);

-

What are the three clauses of a test?

-

Given (some context)

// Given
String name = "Leon";
Integer age = 25;
Person leon = new Person(name, age);

-

When (some action is carried out)

// When
String getNameResult = leon.getName();
Integer getAgeResult = leon.getAge(); 

-

Then (consequences should be observable)

// Then
Assert.assertEquals(name, getNameResult);
Assert.assertEquals(age, getAgeResult);

-