Refactor Code

  • Gravatar
    Using MbUnit RowTest And Row Attribute to Create Multiple Tests

    by azamsharp on 6/2/2008 8:04:53 PM
  • Sometimes we need to unit tests depending on the input supplied by the user. This leads to written multiple unit tests which are testing the same method but with different inputs. The MbUnit RowTest and Row attributes automatically creates multiple tests based on the input. All you need to do is to supply the input parameters from the Row[] attribute. Check out the code below:
  • [RowTest]
    [Row("","","",3)]
    [Row("john","","",2)]
    [Row("john","Senior Consultant","",1)]
    [Row("john","Senior Consultant","2122",0)]
    public void should_get_not_null_or_empty_broken_rules_for_customer_name_title_phone(
    string name, string title, string phone,int result)
    {
    Customer customer = new Customer() { Name = name, Title = title, Phone = phone };
    validationEngine.Validate<Customer>(customer);

    Assert.AreEqual(result, validationEngine.BrokenRules.Count());
    }
  • Refactor it!
Please log in to refactor the code! Login