RequiresTm1EngineFactAttribute
using Skipcheck.Tm1.Testcontainers.Xunit; Runs a test class or method against a real TM1 v12 engine, and skips it when there
isn't one. For TM1 11, use RequiresTm1FactAttribute.
Tests are skipped, not failed, when Docker isn't available or no
Tm1EngineSource is configured, so a build without IBM software stays green. A
source that is configured but wrong fails instead.
One engine serves the whole test JVM (Tm1EngineContainer.SharedAsync), and each
test class gets a database of its own, created when the class first asks for it and
dropped when the class is done. So classes don't see each other's objects. Declare a
Tm1Database parameter on a test method, constructor or lifecycle method to get
it; a Tm1EngineContainer parameter gets the engine.
// A database of this class's own, dropped when the class is done
public sealed class CubeTests(Tm1DatabaseFixture<CubeTests> tm1) : IClassFixture<Tm1DatabaseFixture<CubeTests>>
{
[RequiresTm1EngineFact]
public async Task ListsCubes()
{
var db = tm1.Database;
// The login's session cookie goes on the request, so the client keeps none of its own
using var http = new HttpClient(new HttpClientHandler { UseCookies = false });
using var request = new HttpRequestMessage(HttpMethod.Get, db.RestUrl + "Cubes?$select=Name");
using var response = await http.SendAsync(await db.Login().AuthorizeAsync(request));
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
}
}
A database takes about 13 seconds to create and 5 to drop. ShareDatabaseAsync gives
a class the engine's one shared database instead, at no cost: its tests then need
uniquely named objects, and to delete them afterwards:
// The engine's one shared database instead: nothing to create, but give what you make a unique name
public sealed class ServerNameTests(Tm1EngineFixture tm1) : IClassFixture<Tm1EngineFixture>
{
[RequiresTm1EngineFact]
public async Task ReadsTheServersName()
{
var db = tm1.Database;
using var http = new HttpClient(new HttpClientHandler { UseCookies = false });
using var request = new HttpRequestMessage(HttpMethod.Get, db.RestUrl + "Configuration/ServerName/$value");
using var response = await http.SendAsync(await db.Login().AuthorizeAsync(request));
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
}
}
"A test class" is the unit each language's test framework shares set-up over: a JUnit class here (with its nested classes), a module in pytest, a class in xUnit, and a file in vitest.
Members
NoSourceMessage static | Why a test is skipped without a source. |
RequiresTm1EngineFactAttribute constructor | Skips unless there's a TM1 v12 engine to test against. |
EngineSkipReason static | Why a TM1 v12 test is skipped, or null to run it (a wrong source runs it, to fail). |
NoSourceMessage
staticconst string NoSourceMessageWhy a test is skipped without a source.
RequiresTm1EngineFactAttribute
constructorRequiresTm1EngineFactAttribute()Skips unless there's a TM1 v12 engine to test against.
EngineSkipReason
staticstring? EngineSkipReason()Why a TM1 v12 test is skipped, or null to run it (a wrong source runs it, to fail).