Forum Discussion

alexpat's avatar
alexpat
Occasional Contributor
14 years ago

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

  • tristaanogre's avatar
    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.
  • tristaanogre's avatar
    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.