jeudi 13 février 2020

Why are tests not evaluating properly even if the function is working properly?

I have added MSTests to my C# WinForms project. To test if they are working right, I wanted to test the following function:

public static bool IsValidEmail(string email)
{
    return new EmailAddressAttribute().IsValid(email);
}

To do this I have written these two tests:

[TestMethod]
public void Test_IsValidEmail_True()
{
    Assert.IsTrue(IsValidEmail("test@test.pl"),"Good mail test");
}
[TestMethod]
public void Test_IsValidEmail_False()
{
    Assert.IsFalse(IsValidEmail("test@test"), "Bad mail test");
}

The function works correctly and checks if the email is correct. However the second test passes only if I input it with for example "test", but if I input "test@test" it will not pass and outputs:

Message: Assert.IsFalse failed. Bad mail test

Why is this test failing?

Aucun commentaire:

Enregistrer un commentaire