Home - Ag2S/Tasty GitHub Wiki

Prelude

For experienced programmers, writing test case is such a boring work. In most case, writing test case is nothing but copy-and-paste. For instance, testing a string concatenation class.

public class Concatenator
{
    public string Concatenate(string a, string b)
    {
        if (a == null || b == null)
            throw new ArgumentNullException();

        return a.Concat(b);
    }
}

A successful test case will be defined first, and some failed cases such as a is null and so on. Developers then copy the codes for the Concatenator instance creation and test data, a and b, preparation, modifying the different, and pasting to the failed cases. Duplicated codes!!!


Tasty is not a test framework but an enhancement.

It features:

  • Test framework independent.
    Tasty only defines the flow, i.e. how a test goes. One can choose his own test framework to define test cases.
    It is easy to substitute MSTest to other test framework such as NUnit.

  • Providing test data and mock object container
    Tasty provides containers for test data and mock object. One who uses Tasty could define the test data for the successful test, and only need to define the different for the failed cases.

      [TestClass]
      public class AdditionTests : SubjectBasedTests<Concatenator>
      {
          [TestInitialize]
          public void Initialize()
          {
              InitializeTest();
          }
    
          [TestCleanUp]
          public void Initialize()
          {
              CleanUpTest();
          }
    
          protected override void ArrangeDefault()
          {
              TestData.Of<string>("a").Value = "a";
              TestData.Of<string>("b").Value = "b";
          }
          
          protected override void TestDefault()
          {
              TestData.Of<string>("result").Value = Subject.Concatenate(TestData.Of<string>("a").Value, TestData.Of<string>("b").Value);
          }
          
          [TestMethod]
          public void SuccessTest()
          {
              StartTest()
                  .WithDefaultArrangement()
                  .ThatTestDefault()
                  .Then(() =>
                  {
                      Assert.AreEqual("ab", TestData.Of<int>("z").Value);
                  });
          }
          
          [TestMethod]
          public void BIsNullTest()
          {
              StartTest()
                  .WithDefaultArrangementAndAdditionally(() => {
                      TestData.Of<string>("b").Value = null;
                  })
                  .That(() => {
                      try {
                          TestDefault();
                      }
                      catch(Exception exception)
                      {
                          TestData.Of<Eception>("exception").Value = exception;
                      }
                  })
                  .Then(() => {
                      Assert.IsInstanceOfType(TestData.Of<Exception>("exception").Value, typeof(ArgumentNullException));
                  });
          }
      }
    

For more information, please contact me<[email protected]>.

⚠️ **GitHub.com Fallback** ⚠️