skipcheck

TM1 Testcontainers · Docs · Writing tests

RequiresTm1FactAttribute

using Skipcheck.Tm1.Testcontainers.Xunit;

Used in the walkthrough Test your code against a real TM1.

Runs a test class or method against a real TM1 server, and skips it when there isn't one.

Tests are skipped, not failed, when Docker isn't available or no Tm1Source is configured, so a build without IBM software (such as GitHub CI) stays green. A source that is configured but wrong, such as a folder with no TM1 in it, fails instead.

Declare a Tm1ServerContainer parameter on a test method, constructor or lifecycle method to get the shared container, started on first use.

Tests share one server, so each test should create its own uniquely named objects and delete them afterwards. A test class that sets up a client once and cleans up after each test:

// Every class with this fixture gets the same server, started once for the run
public sealed class RegionDimensionTests(Tm1ServerFixture server) : IClassFixture<Tm1ServerFixture>
{
    [RequiresTm1Fact]
    public async Task CreatesTheRegions()
    {
        await using var tm1 = server.Client();
        // The server is shared, so use a unique name and delete it afterwards
        var region = "Region-" + Guid.NewGuid();
        try
        {
            var created = await tm1.Dimensions.CreateAsync(
                DimensionPatch
                    .Builder()
                    .Name(region)
                    .Hierarchies([
                        HierarchyPatch
                            .Builder()
                            .Name(region)
                            .Elements([
                                ElementPatch.Builder().Name("North").Type(ElementType.Numeric).Build(),
                                ElementPatch.Builder().Name("South").Type(ElementType.Numeric).Build(),
                            ])
                            .Build(),
                    ])
                    .Build()
            );
            Assert.Equal(region, created.Name);
        }
        finally
        {
            try
            {
                await tm1.Dimensions.DeleteAsync(region);
            }
            catch (Tm1NotFoundException)
            {
                // Never created
            }
        }
    }
}

A test that only applies to some TM1 versions checks the server's and skips:

public sealed class NewFeatureTests(Tm1ServerFixture server) : IClassFixture<Tm1ServerFixture>
{
    [RequiresTm1Fact]
    public void NeedsARecentServer()
    {
        // xUnit 2 can't skip a test that has started, so on a server older than the
        // feature the test ends here rather than failing
        var introducedIn = Tm1Version.Parse("11.8.03000");
        if (server.Tm1Server.Tm1Version.IsBefore(introducedIn))
        {
            return;
        }
        // ...
    }
}

Members

NoSourceMessage staticWhy a test is skipped without a source.
NoDockerMessage staticWhy a test is skipped without Docker.
RequiresTm1FactAttribute constructorSkips unless there's TM1 to test against.
Tm1SkipReason staticWhy a TM1 test is skipped, or null to run it (a wrong source runs it, to fail).

NoSourceMessage

static
const string NoSourceMessage

Why a test is skipped without a source.

NoDockerMessage

static
const string NoDockerMessage

Why a test is skipped without Docker.

RequiresTm1FactAttribute

constructor
RequiresTm1FactAttribute()

Skips unless there's TM1 to test against.

Tm1SkipReason

static
string? Tm1SkipReason()

Why a TM1 test is skipped, or null to run it (a wrong source runs it, to fail).