Ask a Question

Best practice for this scenario?

alexpat
Occasional Contributor

Best practice for this scenario?

I have a test that checks that a specific error message shows up if either an invalid email address is entered or if the email address entered already exists in the database and passes.



What would be the "best practice" way of re-using the test so that if I passed in data that I know is correct (specifically an email that isn't in the database and is formatted correctly) that the test still passes.



Would you recommend a separate test or I was thinking that I could pass in a value which would either be True or False depending on what I would want the test to do and change the way the logic in the test works?



Are there any benefits of choosing on way over the other?
2 REPLIES 2
tristaanogre
Esteemed Contributor

Okay, so, as I understand it you want a test that:



1)  Takes one parameter that is the data to be used for the test (an e-mail address)

2)  Inputs the data into the AUT

3)  Checks for the error message

4)  Determines, using potentially another parameter, whether the test passed. 



So, I see something like this (delphiscript)



function TestEmail(EmailAddress, AddressIsValid):boolean;



var

     AppAUT,

     EditForm,

     ErrorForm;



begin

AppAUT := Sys.Process('MyApp');

EditForm := AppAUT.VCLObject('EmailInputForm');

EditForm.EmailEdit.wText := EmailAddress;

EditForm.OKButton.ClickButton;

ErrorForm := AppAut.WaitVCLObject('ErrorMessageWindow', 5000);

//If the address is valid but we get the error message, then the test failed

if AddressIsValid then begin

    Result := AddressIsValid and (not ErrorForm.Exists)

else

    Result := AddressIsValid and ErrorForm.Exists;

end;



That's just a rough-out.  May need some tweaking but that's how I'd handle it.

Robert Martin
[Hall of Fame]
Please consider giving a Kudo if I write good stuff
----

Why automate?  I do automated testing because there's only so much a human being can do and remain healthy.  Sleep is a requirement.  So, while people sleep, automation that I create does what I've described above in order to make sure that nothing gets past the final defense of the testing group.
I love good food, good books, good friends, and good fun.

Mysterious Gremlin Master
Vegas Thrill Rider
Extensions available
tristaanogre
Esteemed Contributor

Oops.  That last check should simply read



Result := Error.Exists;



Because, at that point, we just want to make sure that the form pops up.



Hope this helps.

Robert Martin
[Hall of Fame]
Please consider giving a Kudo if I write good stuff
----

Why automate?  I do automated testing because there's only so much a human being can do and remain healthy.  Sleep is a requirement.  So, while people sleep, automation that I create does what I've described above in order to make sure that nothing gets past the final defense of the testing group.
I love good food, good books, good friends, and good fun.

Mysterious Gremlin Master
Vegas Thrill Rider
Extensions available
cancel
Showing results for 
Search instead for 
Did you mean: