Misuse of assertThat
Opened this issue · 0 comments
Some students discovered a problem about assertThat, turns out it is an unintentional bug. Our TA manage to find this issue and here is his finding. I copy this word below and promise a fix :)
Kevin
Dear Students,
Referring to the question about API assertThat() you asked on the lab, I found the following answer:
The problem comes from API misusing, one misuse example could be seen in the following figure, which is exactly what we have discussed on the lab.
@Test
public void testFound1() throws Excpetion {
boolean thrown = false;
String result = null;
try {
result = this.databaseEngine.search("Hi");
} catch (Exception e) {
thrown = true;
}
assertThat(0 == 1);
assertThat(!thrown);
assertThat(result.equals("Hey, how things going?");
}
Basically, all the 3 assertThat()s cannot work because they are misused. No matter what you assert in this way, the test will always pass. The right way to use it is illustrated in the following figure.
assertThat(0 == 1).isEqualTo(true);
assertThat(!thrown).isEqualTo(true);
assertThat(result).isEqual("Hey, how things going?");
Hope you can see the difference. The test would fail in this way. For more API documentation and API usage examples, please refer to the following urls:
API documentation: http://joel-costigliola.github.io/assertj/core-8/api/index.html
API usage example: http://joel-costigliola.github.io/assertj/
Hope this answer helpful to you.
Best regards,
Jiajun