Using your customised messages in Twist assertions.

I am sure many of you would have felt the need of what I am going to write. Since, Twist uses Junit assertions methods for the assertions, so as it is dependent on Junit to pass on the error messages in case of failures.

Take an example where I am verifying a value of textbox name "Username" and use a Jnunit assertion like

assertEquals (Expected, seleneium.getText("Username"));

In case this step fails, it is going to show like ..

"Expected ['xyz'] but was ['yxz']", but this does not give me any information of the application context.

This becomes even more difficult, when we have a large test suite of big tests and looking at error message it is dificult to figure out, what failed exactly?

So, I would like to see an error message for the above example like -
"Username text expected [xyz], but was [yxz]", and this can be achieved by passing a context (String parameter), to the assertEquals method and then it will generate an error message with the context (Sring parameter). SO, I change the above bit of code to look like this....

assertEquals ("Username text", Expected, seleneium.getText("Username"));

And when this assertion fails, it will generate the error message in more meaning way, and also Twist HTML report will also change accordingly.

This is the simplest way we could do it so far, but I am sure Twist team is working on having its own assertion libraries and I am looking forward to that.

0 comments:

Post a Comment