From b28fa344f7c0788315ced770f329858745da1df0 Mon Sep 17 00:00:00 2001 From: Paul Irwin Date: Wed, 13 Nov 2024 07:28:22 -0700 Subject: [PATCH] Improve message for unit test failures for lucene.testsettings.json, #999 (#1021) --- .../Util/LuceneTestCase.cs | 53 +++++++++++++------ 1 file changed, 38 insertions(+), 15 deletions(-) diff --git a/src/Lucene.Net.TestFramework/Util/LuceneTestCase.cs b/src/Lucene.Net.TestFramework/Util/LuceneTestCase.cs index 210aa689a0..d3c7ec6916 100644 --- a/src/Lucene.Net.TestFramework/Util/LuceneTestCase.cs +++ b/src/Lucene.Net.TestFramework/Util/LuceneTestCase.cs @@ -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" + - $"\n" + - $" \n" + - $" \n" + - $" \n" + - $" \n" + - $"\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: + + + + + + + + + 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); } }