Skip to content

Is it possible to run each test isolated in a separate process? #1796

Answered by thomhurst
siegfriedpammer asked this question in Q&A
Discussion options

You must be logged in to vote

It'd be slow spawning new processes - But my first thought would be you could create a custom executor which executes your test project again with a specific filter for that one test.

public class Tests
{
    [TestExecutor<SeparateProcessExecutor>]
    [Test]
    public async Task Test()
    {
        // ...
    }
}

public class SeparateProcessExecutor : ITestExecutor
{
    public static bool IsSeparateProcess => Environment.GetEnvironmentVariable("IS_SEPARATE_PROCESS") == "true";
    public Task ExecuteTest(TestContext context, Func<Task> action)
    {
        if (IsSeparateProcess)
        {
            return action();
        }
        
        var testDetails = context.TestDetails;

Replies: 1 comment 3 replies

Comment options

You must be logged in to vote
3 replies
@siegfriedpammer
Comment options

@thomhurst
Comment options

@siegfriedpammer
Comment options

Answer selected by siegfriedpammer
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants