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.
That means that the funtcion IsValidEmail("test@test")
returns false
. 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?
Here is how I tested the function if it works manually:
MessageBox.Show("test@test.pl - " + IsValidEmail("test@test.pl"));
MessageBox.Show("test@test - " + IsValidEmail("test@test"));