E2ESetupAttribute
Namespace: E2E.TUnit
public sealed class E2ESetupAttribute : Attribute, ISessionSetup, ITestDiscoveryEventReceiver, IEventReceiverMarks a test of an E2ETest class as a setup test that saves sessions. Upstream’s test.setup(title, { sessions }, fn).
It goes beside [Test] (TUnit does not let a library define a test attribute), and Title becomes the test’s display name. Its body signs in and calls
SaveSessionAsync once for each name in Saves; a name saved twice, a name not declared, or a declared name left
unsaved fails the test with SESSION_CONTRACT. The sessions are saved when the test passes. A test that restores one is marked
E2ESessionAttribute.
<p>
A test that restores a session nobody has saved yet runs the setup test that declares it first, once per run, so a dependent can run
alone (upstream’s runner schedules the setup too). The dependent runs it on a new instance of the class (parameterless constructor), in a
session of its own and without the class’s own [Before(Test)] and [After(Test)] hooks; exactly one setup test of the assembly must
declare the name, or the restore fails with SESSION_UNAVAILABLE, as it does when the setup fails. TUnit then skips that setup test
when its turn comes, and still runs one that no selected test needs, which upstream’s runner does not. The setup test gets the highest
execution priority, so TUnit schedules it before the other tests.
</p>
<p>
TUnit runs tests in parallel, so the setup test and a test that restores its session can start at the same moment, and the setup
then runs twice (once for the dependent, once as its own test). Put [NotInParallel] on the class when it must not.
</p>
Inheritance: object → Attribute
Implements: ISessionSetup, ITestDiscoveryEventReceiver, IEventReceiver
Constructors
Section titled “Constructors”E2ESetupAttribute(string)
Section titled “E2ESetupAttribute(string)”public E2ESetupAttribute(string title)Creates a setup test named <code class=“paramref”>title</code>.
Parameters
| Name | Type | Description |
|---|---|---|
title |
string |
Properties
Section titled “Properties”public int Order { get; }Gets the execution order of this event receiver.
Value: int — The order value as an integer. Default is 0.
Lower values run earlier in the event processing sequence. This allows prioritizing certain event receivers over others.
public string[] Saves { get; init; }The names of the sessions this test saves. At least one.
Value: string[]
public string Title { get; }The test’s name.
Value: string
Methods
Section titled “Methods”OnTestDiscovered(DiscoveredTestContext)
Section titled “OnTestDiscovered(DiscoveredTestContext)”public ValueTask OnTestDiscovered(DiscoveredTestContext context)Names the test and schedules it first.
Parameters
| Name | Type | Description |
|---|---|---|
context |
DiscoveredTestContext |
Returns: ValueTask