Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve message for unit test failures for lucene.testsettings.json, #999 #1021

Merged
merged 2 commits into from
Nov 13, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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:
paulirwin marked this conversation as resolved.
Show resolved Hide resolved

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
Loading