Extensions to the Microsoft Visual Studio Team Test unit testing framework
Перейти к файлу
microsoft-github-policy-service[bot] d4da34f593
Microsoft mandatory file
2022-08-30 09:37:37 +00:00
build Baseline porting of the codebase 2018-04-21 13:25:11 -07:00
src Fixes package references for .NET Standard 2018-04-21 16:01:12 -07:00
test Baseline porting of the codebase 2018-04-21 13:25:11 -07:00
.editorconfig Baseline porting of the codebase 2018-04-21 13:25:11 -07:00
.gitattributes Baseline porting of the codebase 2018-04-21 13:25:11 -07:00
.gitignore Initial commit 2018-04-20 11:15:07 -07:00
LICENSE Initial commit 2018-04-20 11:15:11 -07:00
README.md Add build badge 2018-04-21 13:56:24 -07:00
SECURITY.md Microsoft mandatory file 2022-08-30 09:37:37 +00:00
after.mstestex.sln.targets Update build to support expanding target files to by signed by TFM 2018-04-21 14:59:37 -07:00
mstestex.sln Baseline porting of the codebase 2018-04-21 13:25:11 -07:00
nuget.config Baseline porting of the codebase 2018-04-21 13:25:11 -07:00

README.md

VSTS Build Status

Microsoft Test Framework Extensions

This project provides extensions to the Microsoft Visual Studio Team Test unit testing framework. Features include alternatives to ExpectedExceptionAttribute and a fully extensible assertion application programming interface. The extensibility model is designed to allow swapping out the default Assert class and still maintain source code compatibility with the same intrinsic built-in functionality. You're then free to change, customize, or leverage the many built-in extensions.

Example Usage

To switch from a typical assertion model to the extensible assertion model, simply have your test class inherit from the UnitTest base class. This isn't a requirement to make things work, but it's the simplest model for consumption out-of-the-box.

using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
        
public class Person
{
    public Person( string name ) =>
        Name = name ?? throw new ArgumentNullException( nameof( name ), "The name cannot be null." );
            
    public string Name { get; }
}
        
[TestClass]
public class PersonTest : UnitTest
{
    [TestMethod]
    public void ConstructorShouldNotAllowNullName()
    {
        Assert.ThrowsIfArgumentNull( ( string name ) => new Person( name ) )
              .Verify( e => e.Message == "The name cannot be null." );
    }
}

If you don't want to use a base class, simply add a property to your existing test class:

[TestClass]
public class PersonTest
{
    Asserter Assert { get; } = new Asserter();

    [TestMethod]
    public void ConstructorShouldNotAllowNullName()
    {
        // arrange
        var person = new Person( "Bob" );

        // act
        var result = person.Name;

        // assert
        Assert.AreEqual( "Bob", result );
    }
}

Features

The following outlines the features and extensions provided out-of-the-box:

  • Asserter - Base assertion class and adapts over Assert for its default implemention
  • CollectionAsserter - Collection assertion class and adapts over CollectionAssert for its default implemention
  • ExceptionAsserter - Exception assertion class to further verify parameter names, messages, etc
  • IEnumerable<T> - Extension methods to verify various implementations of collections and sequences
  • INotifyPropertyChanged - Extension methods to verify implementations of the INotifyPropertyChanged interface
  • INotifyCollectionChanged - Extension methods to verify implementations of the INotifyCollectionChanged interface

Contributing

This project welcomes contributions and suggestions. Most contributions require you to agree to a Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us the rights to use your contribution. For details, visit https://cla.microsoft.com.

When you submit a pull request, a CLA-bot will automatically determine whether you need to provide a CLA and decorate the PR appropriately (e.g., label, comment). Simply follow the instructions provided by the bot. You will only need to do this once across all repos using our CLA.

This project has adopted the Microsoft Open Source Code of Conduct. For more information see the Code of Conduct FAQ or contact opencode@microsoft.com with any additional questions or comments.