Class WorkItem
A WorkItem may be an individual test case, a fixture or a higher level grouping of tests. All WorkItems inherit from the abstract WorkItem class, which uses the template pattern to allow derived classes to perform work in whatever way is needed.
A WorkItem is created with a particular TestExecutionContext and is responsible for re-establishing that context in the current thread before it begins or resumes execution.
public abstract class WorkItem : IDisposable
- Inheritance
-
WorkItem
- Implements
- Derived
- Inherited Members
Constructors
WorkItem(WorkItem)
Construct a work Item that wraps another work Item. Wrapper items are used to represent independently dispatched tasks, which form part of the execution of a single test, such as OneTimeTearDown.
public WorkItem(WorkItem wrappedItem)
Parameters
wrappedItem
WorkItemThe WorkItem being wrapped
WorkItem(Test, ITestFilter)
Construct a WorkItem for a particular test.
public WorkItem(Test test, ITestFilter filter)
Parameters
test
TestThe test that the WorkItem will run
filter
ITestFilterFilter used to include or exclude child items
Properties
Context
The execution context
public TestExecutionContext Context { get; }
Property Value
ExecutionStrategy
The ParallelExecutionStrategy to use for this work item
public virtual ParallelExecutionStrategy ExecutionStrategy { get; }
Property Value
Filter
Filter used to include or exclude child tests
public ITestFilter Filter { get; }
Property Value
IsolateChildTests
Indicates whether this work item should use a separate dispatcher.
public virtual bool IsolateChildTests { get; }
Property Value
Name
The name of the work item - defaults to the Test name.
public virtual string Name { get; }
Property Value
ParallelScope
Gets the ParallelScope associated with the test, if any, otherwise returning ParallelScope.Default;
public ParallelScope ParallelScope { get; }
Property Value
Result
The test result
public TestResult Result { get; protected set; }
Property Value
State
Gets the current state of the WorkItem
public WorkItemState State { get; protected set; }
Property Value
Test
The test being executed by the work item
public Test Test { get; }
Property Value
TestWorker
The worker executing this item.
public TestWorker? TestWorker { get; }
Property Value
Methods
BuildSetUpTearDownList(IMethodInfo[], IMethodInfo[], IMethodValidator?)
Builds the set up tear down list.
protected List<SetUpTearDownItem> BuildSetUpTearDownList(IMethodInfo[] setUpMethods, IMethodInfo[] tearDownMethods, IMethodValidator? methodValidator = null)
Parameters
setUpMethods
IMethodInfo[]Unsorted array of setup MethodInfos.
tearDownMethods
IMethodInfo[]Unsorted array of teardown MethodInfos.
methodValidator
IMethodValidatorMethod validator used before each method execution.
Returns
- List<SetUpTearDownItem>
A list of SetUpTearDownItems
Cancel(bool)
Cancel (abort or stop) a WorkItem
public virtual void Cancel(bool force)
Parameters
force
booltrue if the WorkItem should be aborted, false if it should run to completion
ChangeResult(ResultState, string)
Changes the result of the test, logging the old and new states
protected void ChangeResult(ResultState resultState, string message)
Parameters
resultState
ResultStateThe new ResultState
message
stringThe new message
Dispose()
Standard Dispose
public void Dispose()
Execute()
Execute the current work item, including any child work items.
public virtual void Execute()
InitializeContext(TestExecutionContext)
Initialize the TestExecutionContext. This must be done before executing the WorkItem.
public void InitializeContext(TestExecutionContext context)
Parameters
context
TestExecutionContextThe TestExecutionContext to use
Remarks
Originally, the context was provided in the constructor but delaying initialization of the context until the item is about to be dispatched allows changes in the parent context during OneTimeSetUp to be reflected in the child.
MarkNotRunnable(string)
Marks the WorkItem as NotRunnable.
public void MarkNotRunnable(string reason)
Parameters
reason
stringReason for test being NotRunnable.
PerformWork()
Method that performs actually performs the work. It should set the State to WorkItemState.Complete when done.
protected abstract void PerformWork()
WaitForCompletion()
Wait until the execution of this item is complete
public void WaitForCompletion()
WorkItemComplete()
Method called by the derived class when all work is complete
protected void WorkItemComplete()
Events
Completed
Event triggered when the item is complete
public event EventHandler? Completed