Two way assertion

4185 views java
3

I am doing web automation testing, for example lets say I have two very basic scenarios:

Test a) step 1: add record to the database step 2: check if website displayed record properly

Test b) step 1: edit record on the website step 2: check if record were properly saved in database

By record, let say it was simple text field with some "value"

So for first scenario, I would use Assert equal:

private void check1()
{
    Assert.assertEquals(valueFromDB, valueOnWebsite)
    //many more assertions for more values here        
}

but, for second scenario, it would be:

private void check2()
{
    Assert.assertEquals(valueOnWebsite, valueFromDB)
    //many more assertions for more values here        
}

So basically they both do the same, but are inverted, in order to throw correct error log if assertion was incorrect, now how to make it in single method, that could work for both cases, BUT would display correct assertion log if values were not equal?

answered question

You are already using a single method - Assert.assertEquals

but with inverted parameters, in order to get correct assertion log in case two values were no equal.

1 Answer

8

Use the overload which receives a message

String message = "valueFromDB value: " + valueFromDB + ", valueOnWebsite value: " + valueOnWebsite;
Assert.assertEquals(message, valueFromDB, valueOnWebsite);

posted this

Have an answer?

JD

Please login first before posting an answer.