Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

custom error message for assertThat() in junit?

Tags:

java

junit

I was wondering if assertThat() has a way of adding a custom error message ?

for example in this :

assertThat(file.exists(), is(equalTo(true)));

I would like to add some custom message, saying which file name doesnt exist

like image 832
Medya Gh Avatar asked Apr 30 '14 21:04

Medya Gh


1 Answers

I would prefer the following, to avoid the reader believing that you wish to assert that the file name doesn't exist..!

assertThat("File name should exist", file.exists(), is(equalTo(true)));
like image 93
mleonard Avatar answered Sep 18 '22 11:09

mleonard