Table of Contents

BaseTest

BaseTest provides shared assertion helpers and test utilities for MSTest projects. It also provides the base class for the framework's ASP.NET integration test helpers.

Features

  • Test lifecycle: Provides MSTest cleanup and flushes pending framework logs once.
  • Assertions: Includes IsOk, IsEmpty, IsNull, IsException, and other assertion helpers.
  • Polling: When() waits for a condition to become true.
  • Test context: Exposes MSTest's TestContext.

Behavior

TestCleanup() flushes pending logs during the first cleanup and waits briefly for background tasks to finish.

When() checks the condition immediately, then retries every 50ms for up to approximately 10 seconds. Exceptions thrown by the condition are ignored while waiting.

Assertion failures throw exceptions.

Example

public class MyTests : BaseTest
{
    [TestMethod]
    public void TestSomething()
    {
        var result = service.GetValue();

        IsOk(result);
        IsNull(null);
        IsEmpty("");
        IsException(() => service.DoSomethingInvalid());
    }
}

Caveats

  • IsEmpty() checks for an empty string, not empty collections.
  • IsException() only verifies that an exception was thrown; it does not check its type.
  • When() returns false when the condition does not become true within the timeout.