mercredi 17 août 2016

c# unit testing class

Im doing unit testing with a class library and im stuck on how to test the method that need to test scenarios like check if a password with less than 8 characters cannot be accepted, check if a password with 8 or more characters can be accepted and check if a password with space in the front cannot be accepted. The code below is from the class library.

public class PasswordChecker
{
    public bool CheckPassword(string pwd)
{
    if (pwd.Length >= 8 && !pwd.StartsWith(""))
    {
        return true;
    }
    else
    {
        return false;
    }
}
}

The code below is from the testing project.

using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using 12kiajunPA03;

namespace PasswordCheckerTest
{
[TestClass]
public class PasswordCheckerTest
{
    [TestMethod]
    public void Checkpassword()
    {
        string pwd = "1234qa1";

        Checkpassword password = new Checkpassword("John", pwd);

        try
        {

        }
        catch
        {

        }
    }
}

}

Aucun commentaire:

Enregistrer un commentaire