Joined a new employer and came across a new style of writing tests.
@Test()
public testMethodWhichDoesNotDoAnyAssertion() {
LoginPage loginPage = signUpPage.doLogin("username","password");
oneMoreCommonMethodCalledHere()
anotherCommonMethodCalledHere()
}
public void doLogin(String userName, String password) {
//login here
Assert.assertTrue("Login Successful")
}
public void oneMoreCommonMethodCalledHere() {
//Some more operations here.
Assert.assertTrue("This also succeeded")
}
public void anotherCommonMethodCalledHere() {
//Some more operations here.
Assert.assertTrue("Even this succeeded!!! Your code is awesome!!!")
So far I have been doing assertions in tests and not in the methods which are invoked from test method. The problems I have with approach are multiple -
There are two many assertions happening in one method, though indirectly and it defeats the idea of one responsibility per test
There are times when I want to do one assertion in my test method while testing for a work flow. And many of the helper methods which would be called would assert things and might even fail which would hamper work flow test.
Now thing I have heard in favour of this approach - It is easy for any one to just plug in helper method in a test while not worrying about the assertions which should be carried out for a scenario, as helper method takes care of it.
Comments?