Skip to content

Commit

Permalink
Improve message for unit test failures for lucene.testsettings.json, #…
Browse files Browse the repository at this point in the history
  • Loading branch information
paulirwin authored Nov 13, 2024
1 parent 92029e8 commit b28fa34
Showing 1 changed file with 38 additions and 15 deletions.
53 changes: 38 additions & 15 deletions src/Lucene.Net.TestFramework/Util/LuceneTestCase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -929,23 +929,46 @@ public virtual void TearDown()
*/

TestResult result = TestExecutionContext.CurrentContext.CurrentResult;
string message;

if (result.ResultState == ResultState.Failure || result.ResultState == ResultState.Error)
{
message = result.Message + $"\n\nTo reproduce this test result:\n\n" +
$"Option 1:\n\n" +
$" Apply the following assembly-level attributes:\n\n" +
$"[assembly: Lucene.Net.Util.RandomSeed(\"{RandomizedContext.CurrentContext.RandomSeedAsHex}\")]\n" +
$"[assembly: NUnit.Framework.SetCulture(\"{Thread.CurrentThread.CurrentCulture.Name}\")]\n\n" +
$"Option 2:\n\n" +
$" Use the following .runsettings file:\n\n" +
$"<RunSettings>\n" +
$" <TestRunParameters>\n" +
$" <Parameter name=\"tests:seed\" value=\"{RandomizedContext.CurrentContext.RandomSeedAsHex}\" />\n" +
$" <Parameter name=\"tests:culture\" value=\"{Thread.CurrentThread.CurrentCulture.Name}\" />\n" +
$" </TestRunParameters>\n" +
$"</RunSettings>\n\n" +
$"See the .runsettings documentation at: https://docs.microsoft.com/en-us/visualstudio/test/configure-unit-tests-by-using-a-dot-runsettings-file.";
string message =
$$"""
{{result.Message}}

To reproduce this test result:

Option 1:

Apply the following assembly-level attributes:

[assembly: Lucene.Net.Util.RandomSeed("{{RandomizedContext.CurrentContext.RandomSeedAsHex}}")]
[assembly: NUnit.Framework.SetCulture("{{Thread.CurrentThread.CurrentCulture.Name}}")]

Option 2:

Use the following .runsettings file:

<RunSettings>
<TestRunParameters>
<Parameter name="tests:seed" value="{{RandomizedContext.CurrentContext.RandomSeedAsHex}}" />
<Parameter name="tests:culture" value="{{Thread.CurrentThread.CurrentCulture.Name}}" />
</TestRunParameters>
</RunSettings>

Option 3:

Create the following lucene.testsettings.json file somewhere between the test assembly and the root of your drive:

{
"tests": {
"seed": "{{RandomizedContext.CurrentContext.RandomSeedAsHex}}",
"culture": "{{Thread.CurrentThread.CurrentCulture.Name}}"
}
}

""";

result.SetResult(result.ResultState, message, result.StackTrace);
}
}
Expand Down

0 comments on commit b28fa34

Please sign in to comment.