Requirements and Acceptance Test Scenarios

As an example here, the requirement is: As a user, I want to the system have strong password policy. BA has defined that a valid password is that a password must be from 6 to 12 characters long and include at least one letter, at least one digit, and at least one punctuation character. Tester has created acceptance test scenarios in Excel.

tests in excel

Implement the Requirements

Developer has implemented the requirement using regular expression "(?=^.{6,12}$)(?=.*\d)(?=.*\W+)(?![.\n])(?=.*[A..Z,a..z]).*$" .

    public static class PasswordValidator
    {
        /// <summary>
        /// To be valid, a password must be from 6 to 12 characters long and include 
        /// at least one letter, 
        /// at least one digit, and 
        /// at least one punctuation character.
        /// </summary>
        /// <param name="password"></param>
        /// <returns></returns>
        public static bool IsValidPassword(string password)
        {
            if (string.IsNullOrEmpty(password)) return false;
            return Regex.IsMatch(password, @"(?=^.{6,12}$)(?=.*\d)(?=.*\W+)(?![.\n])(?=.*[A..Z,a..z]).*$");
        }
    }

Create Test Library

Now developer will create a test library. Test library contains step definitions. It is a .NET class library having classes and methods that implement the test steps.

    [StepDefinition("Password Test")]
    public class PasswordTestSteps
    {
        private bool isValid;

        [Step(@"^password (.+) is checked$")]
        public void ValidaPassword(string password)
        {
            isValid = PasswordValidator.IsValidPassword(password);
        }

        [Step(@"^it should fail$")]
        public void ItShouldFail()
        {
            if (isValid) throw new Exception("Password is expected to be invalid, but is marked as valid.");
        }

        [Step(@"^it should pass$")]
        public void ItShouldPass()
        {
            if (!isValid) throw new Exception("Password is expected to be valid, but is marked as invalid.");
        }
    }

Compile the test libray and deliver the DLL to testers.

Examples

You can browser or download the source code to see the password validation sample.

How to Get Source Code Using Git

For developers want to use git, here are the steps.
  • Download tfc.exe from codeplex client project
  • Rename cpc.exe to git-cpc.exe
  • Copy git-cpc.exe to C:\Program Files\Git\libexec\git-core or C:\Program Files (x86)\Git\libexec\git-core
  • Start git bash, run the following commands
    • $ git init aat
    • $ cd aat
    • $ git cpc co https://tfs08.codeplex.com $/aat
    • $ git add .
    • $ git commint -m 'get from codeplex'
......



Last edited Mar 24, 2010 at 4:51 PM by yysun, version 5

Comments

No comments yet.