Skip to content

Commit

Permalink
Support new execution structure for xUnit
Browse files Browse the repository at this point in the history
  • Loading branch information
gasparnagy committed Oct 7, 2024
1 parent 1888c88 commit c4880d7
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 12 deletions.
15 changes: 4 additions & 11 deletions Reqnroll.Generator/Generation/UnitTestFeatureGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@ private void SetupTestClassInitializeMethod(TestClassGenerationContext generatio

_testGeneratorProvider.SetTestClassInitializeMethod(generationContext);

/*
//testRunner = TestRunnerManager.GetTestRunnerForAssembly(null, [test_worker_id]);
var testRunnerField = _scenarioPartHelper.GetTestRunnerExpression();
Expand Down Expand Up @@ -208,7 +209,7 @@ private void SetupTestClassInitializeMethod(TestClassGenerationContext generatio
_codeDomHelper.MarkCodeMethodInvokeExpressionAsAwait(onFeatureStartExpression);
testClassInitializeMethod.Statements.Add(onFeatureStartExpression);
testClassInitializeMethod.Statements.Add(onFeatureStartExpression);*/
}

private void SetupTestClassCleanupMethod(TestClassGenerationContext generationContext)
Expand All @@ -221,7 +222,7 @@ private void SetupTestClassCleanupMethod(TestClassGenerationContext generationCo
_codeDomHelper.MarkCodeMemberMethodAsAsync(testClassCleanupMethod);

_testGeneratorProvider.SetTestClassCleanupMethod(generationContext);

/*
var testRunnerField = _scenarioPartHelper.GetTestRunnerExpression();
// await testRunner.OnFeatureEndAsync();
Expand All @@ -244,7 +245,7 @@ private void SetupTestClassCleanupMethod(TestClassGenerationContext generationCo
testClassCleanupMethod.Statements.Add(
new CodeAssignStatement(
testRunnerField,
new CodePrimitiveExpression(null)));
new CodePrimitiveExpression(null)));*/
}

private void SetupTestInitializeMethod(TestClassGenerationContext generationContext)
Expand All @@ -258,10 +259,6 @@ private void SetupTestInitializeMethod(TestClassGenerationContext generationCont

_testGeneratorProvider.SetTestInitializeMethod(generationContext);

if (generationContext.UnitTestGeneratorProvider is not MsTestGeneratorProvider &&
generationContext.UnitTestGeneratorProvider is not NUnit3TestGeneratorProvider)
return; // only MsTest & NUnit is implemented in this prototype

// Step 4: Obtain the test runner for executing a single test

// testRunner = global::Reqnroll.TestRunnerManager.GetTestRunnerForAssembly();
Expand Down Expand Up @@ -373,10 +370,6 @@ private void SetupTestCleanupMethod(TestClassGenerationContext generationContext

testCleanupMethod.Statements.Add(expression);

if (generationContext.UnitTestGeneratorProvider is not MsTestGeneratorProvider &&
generationContext.UnitTestGeneratorProvider is not NUnit3TestGeneratorProvider)
return; // only MsTest & NUnit is implemented in this prototype

// Step 6: "Release" the TestRunner, so that other threads can pick it up (moved from TestClassCleanupMethod)
// TestRunnerManager.ReleaseTestRunner(testRunner);
testCleanupMethod.Statements.Add(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,8 @@ public void SetTestClassInitializeMethod(TestClassGenerationContext generationCo
{
// xUnit uses IUseFixture<T> on the class
generationContext.TestClassInitializeMethod.Attributes |= MemberAttributes.Static;
generationContext.TestRunnerField.Attributes |= MemberAttributes.Static;
// Step 1: make 'testRunner' instance field
// generationContext.TestRunnerField.Attributes |= MemberAttributes.Static;

_currentFixtureDataTypeDeclaration = CodeDomHelper.CreateGeneratedTypeDeclaration("FixtureData");
generationContext.TestClass.Members.Add(_currentFixtureDataTypeDeclaration);
Expand Down Expand Up @@ -245,6 +246,11 @@ public void SetTestClassInitializeMethod(TestClassGenerationContext generationCo
CodeDomHelper.MarkCodeMethodInvokeExpressionAsAwait(expression);

initializeMethod.Statements.Add(expression);


// Step 2: Remove TestClassInitializeMethod (not needed)
generationContext.TestClassInitializeMethod.Statements.Clear();
//generationContext.TestClass.Members.Remove(generationContext.TestClassInitializeMethod);
}

public void SetTestClassCleanupMethod(TestClassGenerationContext generationContext)
Expand Down Expand Up @@ -345,6 +351,10 @@ public void SetTestCleanupMethod(TestClassGenerationContext generationContext)
CodeDomHelper.MarkCodeMethodInvokeExpressionAsAwait(expression);

disposeMethod.Statements.Add(expression);

// Step 3: Remove TestClassCleanupMethod (not needed)
generationContext.TestClassCleanupMethod.Statements.Clear();
//generationContext.TestClass.Members.Remove(generationContext.TestClassCleanupMethod);
}

public void SetTestClassIgnore(TestClassGenerationContext generationContext)
Expand Down

0 comments on commit c4880d7

Please sign in to comment.