agentleFS
MovGP0MovGP0/Skills/unit-testing/SKILL.md

unit-testing

Skill1 starsChanged 5 months agoMITView on GitHub

Guides unit test setup, naming, TestOf usage, Arrange/Act/Assert structure, ServiceLocator initialization, and Shouldy assertions. Use when adding, reviewing, or fixing unit tests.

6 other projects use a version of this.

Adopted by

Most recently taken up by

The file

We split this skill into the rules it gives an agent

4 rules. 0 are common, 0 are distinctive, and 4 are very specific to this project.

  • 0

    Common

    Most of the 5 edited versions we read keep these.

  • 0

    Distinctive

    This author's own choices. Worth a look.

  • 4

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Very specific:

    Use Shouldy for assertions.

    line 44
  2. Very specific:

    Use [TestOf(typeof(ClassName))] on test classes to indicate the class under test.

    line 62
  3. Very specific:

    Use [TestOf(typeof(ClassName), nameof(ClassName.MethodName))] or [TestOf(typeof(ClassName), nameof(ClassName.PropertyName))] for nested …

    line 63
  4. Very specific:

    Use the ILObjectNames class for special .NET objects like operators and constructors.

    line 64

“Common” is measured: kept by at least 6 in 10 of the 5 edited versions of this file we could read. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Unit Testing

Test setup

  • You may need to initialize a unit test with a ServiceLocator. Especially for logging:
[TestOf(typeof(SettingsProvider), nameof(SettingsProvider.LoadSettings))]
public sealed class LoadSettingsTests: IDisposable
{
    public LoadSettingsTests(ITestOutputHelper testOutputHelper)
    {
        ServiceLocator.Cleanup();
        ServiceLocator.Initialize(services =>
        {
            services.AddLogging(logger =>
            {
                logger.SetMinimumLevel(LogLevel.Debug);
                logger.AddXUnit(testOutputHelper);
            });
        });
    }

    public void Dispose() => ServiceLocator.Cleanup();

    // tests come here...
  • The name of a test (Fact/Theory) should start with the name "Should", followed by the expected result and the action taken. Setting the DisplayName property improves readability.
[Fact(DisplayName = "Should return user settings when invoked")]
public void ShouldReturnUserSettingsWhenInvoked()
  • Structure the unit tests using // Arrange, // Act and // Assert comments. You may also use // Cleanup or // Arrange & Act or // Act & Assert in rare situations.
  • Name the object beeing testet as subject and the (primary) result value result:
// Arrange
var subject = new SomeTypeUnderTest();

// Act
var result = subject.DoSomething();
  • Use Shouldy for assertions. Use one assertion only, but you may use ShouldSatisfyAllConditions when multiple assertions are required:
result.ShouldSatisfyAllConditions(
    () => /* first assertion */,
    () => /* second assertion */,
    () => /* third assertion */,
    // add more assertions as required
);
  • You may also nest assertions:
result.ShouldSatisfyAllConditions(
    () => result.Value.ShouldNotBeNull().ShouldBe("foobar"),
    // add more assertions as required
);

Usage of [TestOf] Attribute

  • Use [TestOf(typeof(ClassName))] on test classes to indicate the class under test.
  • Use [TestOf(typeof(ClassName), nameof(ClassName.MethodName))] or [TestOf(typeof(ClassName), nameof(ClassName.PropertyName))] for nested test classes.
  • Use the ILObjectNames class for special .NET objects like operators and constructors.

Examples:

[TestOf(typeof(TypeUnderTest)]
public static class TypeUnderTestTests
{
    [TestOf(typeof(TypeUnderTest), ILObjectNames.Constructor)]
    public sealed class ConstructorTests { /* ... */ }

    [TestOf(typeof(TypeUnderTest), ILObjectNames.Deconstructor)]
    public sealed class DeconstructorTests { /* ... */ }

    [TestOf(typeof(TypeUnderTest), ILObjectNames.Indexer)]
    public sealed class IndexerTests { /* ... */ }

    [TestOf(typeof(TypeUnderTest), ILObjectNames.op_Addition)]
    public sealed class AdditionOperatorTests { /* ... */ }

    [TestOf(typeof(TypeUnderTest), ILObjectNames.op_MultiplicationAssignment)]
    public sealed class MultiplicationAssignmentOperatorTests { /* ... */ }

    [TestOf(typeof(TypeUnderTest), ILObjectNames.op_GreaterThanOrEqualAssignment)]
    public sealed class GreaterThanOrEqualAssignmentOperatorTests { /* ... */ }

    [TestOf(typeof(TypeUnderTest), ILObjectNames.op_Implicit)]
    public sealed class ImplicitOperatorTests { /* ... */ }

    [TestOf(typeof(TypeUnderTest), ILObjectNames.op_Explicit)]
    public sealed class ExplicitOperatorTests { /* ... */ }
}

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.