Stefan M.
3 min readFeb 18, 2016

--

German time: 14:45 Uhr
American time: 2.45 PM
German time with date: 14:45 Uhr, Freitag 12.02.2016
American time with date: 2.45 PM, Friday 12.02.2016
Test class first — then implementation
Get the help from your IDE
Again — get help from your IDE
@Test
public void testName() throws Exception {
MyClock clock = new MyClock();

String germanTime = clock.getCurrentTime();

assertThat(germanTime, is(equalTo("14:45 Uhr")));
}
testGetCurrentName_ShouldReturnTimeInGermanFormat()
public String getCurrentTime() {
return "14:45 Uhr";
}
@Test
public void testGetCurrentName_ShouldReturnTimeInAmericanFormat() throws Exception {
MyClock clock = new MyClock();

String americanTime = clock.getCurrentTime();

assertThat(americanTime, is(equalTo("2:45 PM")));
}
java.lang.AssertionError: 
Expected: is “2:45 PM”
but: was “14:45 Uhr”
public enum TimeFormat {
GERMAN, AMERICAN
}
@Test
public void testGetCurrentName_ShouldReturnTimeInGermanFormat() throws Exception {
MyClock clock = new MyClock();

String germanTime = clock.getCurrentTime(TimeFormat.GERMAN);

assertThat(germanTime, is(equalTo("14:45 Uhr")));
}

@Test
public void testGetCurrentName_ShouldReturnTimeInAmericanFormat() throws Exception {
MyClock clock = new MyClock();

String americanTime = clock.getCurrentTime(TimeFormat.AMERICAN);

assertThat(americanTime, is(equalTo("2:45 PM")));
}
public String getCurrentTime(TimeFormat format) {
switch (format) {
case GERMAN:
return "14:45 Uhr";
case AMERICAN:
return "2:45 PM";
default:
return "";
}
}
private MyClock mMyClock;

@Before
public void setUp() throws Exception {
mMyClock = new MyClock();
}

--

--