Skip to content

Enforce architectural rules by documenting expectations as tests.

License

Notifications You must be signed in to change notification settings

Testably/Testably.Architecture.Rules

Repository files navigation

Testably.Architecture.Rules
Nuget Build Codacy Badge Coverage Mutation testing badge

This library is used to define architecture rules as expectations that can be run and checked as part of the unit test execution.

Examples

  • Test classes should have Tests as suffix:

    [Fact]
    public void ExpectTestClassesToBeSuffixedWithTests()
    {
      IRule rule = Expect.That.Types
          .Which(Have.Method.WithAttribute<FactAttribute>().OrAttribute<TheoryAttribute>())
          .ShouldMatchName("*Tests");
    
      rule.Check
          .InAllLoadedAssemblies()
          .ThrowIfViolated();
    }
  • Methods that return Task should have Async as suffix:

    [Fact]
    public void AsyncMethodsShouldHaveAsyncSuffix()
    {
      IRule rule = Expect.That.Methods
        .WithReturnType<Task>().OrReturnType(typeof(Task<>))
        .ShouldMatchName("*Async")
        .AllowEmpty();
    
      rule.Check
        .InTestAssembly()
        .ThrowIfViolated();
    }

About

Enforce architectural rules by documenting expectations as tests.

Resources

License

Code of conduct

Stars

Watchers

Forks

Packages

No packages published

Languages