From 75ee707a720fb560193f73aa494e096e5205b636 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Jare=C5=A1?= Date: Wed, 20 May 2026 16:23:07 +0200 Subject: [PATCH 1/2] Fix datacollector crash visibility: replace Assert with throwable exceptions When TestElement is null in TestCaseStarted/TestCaseEnded, TPDebug.Assert calls Debug.Assert which in debug builds terminates the process via Environment.FailFast, bypassing the try-catch in DataCollectionTestCaseEventHandler.ProcessRequests. This makes errors very hard to see. Replace the TPDebug.Assert null checks with explicit if/throw so the InvalidOperationException is caught by ProcessRequests, reported via _messageSink.SendMessage as a visible error, and the test run continues cleanly instead of crashing. Fixes #15622 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- .../DataCollection/DataCollectionManager.cs | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/Microsoft.TestPlatform.Common/DataCollection/DataCollectionManager.cs b/src/Microsoft.TestPlatform.Common/DataCollection/DataCollectionManager.cs index 5fdaf63c00..62127127e2 100644 --- a/src/Microsoft.TestPlatform.Common/DataCollection/DataCollectionManager.cs +++ b/src/Microsoft.TestPlatform.Common/DataCollection/DataCollectionManager.cs @@ -317,7 +317,11 @@ public void TestCaseStarted(TestCaseStartEventArgs testCaseStartEventArgs) } TPDebug.Assert(_dataCollectionEnvironmentContext is not null, "_dataCollectionEnvironmentContext is null"); - TPDebug.Assert(testCaseStartEventArgs.TestElement is not null, "testCaseStartEventArgs.TestElement is null"); + if (testCaseStartEventArgs.TestElement is null) + { + throw new InvalidOperationException("TestCaseStartEventArgs.TestElement is null. The data collector cannot start a test case without a test element."); + } + var context = new DataCollectionContext(_dataCollectionEnvironmentContext.SessionDataCollectionContext.SessionId, testCaseStartEventArgs.TestElement); testCaseStartEventArgs.Context = context; @@ -333,7 +337,11 @@ public Collection TestCaseEnded(TestCaseEndEventArgs testCaseEndE } TPDebug.Assert(_dataCollectionEnvironmentContext is not null, "_dataCollectionEnvironmentContext is null"); - TPDebug.Assert(testCaseEndEventArgs.TestElement is not null, "testCaseEndEventArgs.TestElement is null"); + if (testCaseEndEventArgs.TestElement is null) + { + throw new InvalidOperationException("TestCaseEndEventArgs.TestElement is null. The data collector cannot end a test case without a test element."); + } + var context = new DataCollectionContext(_dataCollectionEnvironmentContext.SessionDataCollectionContext.SessionId, testCaseEndEventArgs.TestElement); testCaseEndEventArgs.Context = context; From 3a24949648255ab1aba76d39e7e1d1e8b56ab8c4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Jare=C5=A1?= Date: Mon, 1 Jun 2026 10:58:31 +0200 Subject: [PATCH 2/2] Address review feedback: fix sibling asserts and add tests - Convert all TPDebug.Assert(_dataCollectionEnvironmentContext is not null) calls in SessionStarted, TestCaseStarted, and TestCaseEnded to if/throw InvalidOperationException so errors surface via the messageSink catch block instead of FailFast in debug builds - Use localized resource strings for all new error messages - Add resource strings DataCollectionContextNotInitialized, DataCollectionTestCaseStartMissingTestElement, and DataCollectionTestCaseEndMissingTestElement to Resources.resx, Designer.cs, and all 13 .xlf locale files - Add unit tests: TestCaseStarted/Ended throw InvalidOperationException when TestElement is null, and when _dataCollectionEnvironmentContext is null Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- .../DataCollection/DataCollectionManager.cs | 22 +++++++-- .../Resources/Resources.Designer.cs | 27 +++++++++++ .../Resources/Resources.resx | 9 ++++ .../Resources/xlf/Resources.cs.xlf | 15 ++++++ .../Resources/xlf/Resources.de.xlf | 15 ++++++ .../Resources/xlf/Resources.es.xlf | 15 ++++++ .../Resources/xlf/Resources.fr.xlf | 15 ++++++ .../Resources/xlf/Resources.it.xlf | 15 ++++++ .../Resources/xlf/Resources.ja.xlf | 15 ++++++ .../Resources/xlf/Resources.ko.xlf | 15 ++++++ .../Resources/xlf/Resources.pl.xlf | 15 ++++++ .../Resources/xlf/Resources.pt-BR.xlf | 15 ++++++ .../Resources/xlf/Resources.ru.xlf | 15 ++++++ .../Resources/xlf/Resources.tr.xlf | 15 ++++++ .../Resources/xlf/Resources.zh-Hans.xlf | 15 ++++++ .../Resources/xlf/Resources.zh-Hant.xlf | 15 ++++++ .../DataCollectionManagerTests.cs | 46 +++++++++++++++++++ 17 files changed, 294 insertions(+), 5 deletions(-) diff --git a/src/Microsoft.TestPlatform.Common/DataCollection/DataCollectionManager.cs b/src/Microsoft.TestPlatform.Common/DataCollection/DataCollectionManager.cs index 62127127e2..a4d6889258 100644 --- a/src/Microsoft.TestPlatform.Common/DataCollection/DataCollectionManager.cs +++ b/src/Microsoft.TestPlatform.Common/DataCollection/DataCollectionManager.cs @@ -301,7 +301,11 @@ public bool SessionStarted(SessionStartEventArgs sessionStartEventArgs) return false; } - TPDebug.Assert(_dataCollectionEnvironmentContext is not null, "_dataCollectionEnvironmentContext is null"); + if (_dataCollectionEnvironmentContext is null) + { + throw new InvalidOperationException(Resources.Resources.DataCollectionContextNotInitialized); + } + sessionStartEventArgs.Context = new DataCollectionContext(_dataCollectionEnvironmentContext.SessionDataCollectionContext.SessionId); SendEvent(sessionStartEventArgs); @@ -316,10 +320,14 @@ public void TestCaseStarted(TestCaseStartEventArgs testCaseStartEventArgs) return; } - TPDebug.Assert(_dataCollectionEnvironmentContext is not null, "_dataCollectionEnvironmentContext is null"); + if (_dataCollectionEnvironmentContext is null) + { + throw new InvalidOperationException(Resources.Resources.DataCollectionContextNotInitialized); + } + if (testCaseStartEventArgs.TestElement is null) { - throw new InvalidOperationException("TestCaseStartEventArgs.TestElement is null. The data collector cannot start a test case without a test element."); + throw new InvalidOperationException(Resources.Resources.DataCollectionTestCaseStartMissingTestElement); } var context = new DataCollectionContext(_dataCollectionEnvironmentContext.SessionDataCollectionContext.SessionId, testCaseStartEventArgs.TestElement); @@ -336,10 +344,14 @@ public Collection TestCaseEnded(TestCaseEndEventArgs testCaseEndE return new Collection(); } - TPDebug.Assert(_dataCollectionEnvironmentContext is not null, "_dataCollectionEnvironmentContext is null"); + if (_dataCollectionEnvironmentContext is null) + { + throw new InvalidOperationException(Resources.Resources.DataCollectionContextNotInitialized); + } + if (testCaseEndEventArgs.TestElement is null) { - throw new InvalidOperationException("TestCaseEndEventArgs.TestElement is null. The data collector cannot end a test case without a test element."); + throw new InvalidOperationException(Resources.Resources.DataCollectionTestCaseEndMissingTestElement); } var context = new DataCollectionContext(_dataCollectionEnvironmentContext.SessionDataCollectionContext.SessionId, testCaseEndEventArgs.TestElement); diff --git a/src/Microsoft.TestPlatform.Common/Resources/Resources.Designer.cs b/src/Microsoft.TestPlatform.Common/Resources/Resources.Designer.cs index a6d36bf761..d3942775c7 100644 --- a/src/Microsoft.TestPlatform.Common/Resources/Resources.Designer.cs +++ b/src/Microsoft.TestPlatform.Common/Resources/Resources.Designer.cs @@ -132,6 +132,33 @@ internal static string DataCollectorRequestedDuplicateEnvironmentVariable { } } + /// + /// Looks up a localized string similar to The data collection environment context has not been initialized. Ensure that session started before processing test case events. + /// + internal static string DataCollectionContextNotInitialized { + get { + return ResourceManager.GetString("DataCollectionContextNotInitialized", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to TestCaseStartEventArgs.TestElement is null. The data collector cannot start a test case without a test element. + /// + internal static string DataCollectionTestCaseStartMissingTestElement { + get { + return ResourceManager.GetString("DataCollectionTestCaseStartMissingTestElement", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to TestCaseEndEventArgs.TestElement is null. The data collector cannot end a test case without a test element. + /// + internal static string DataCollectionTestCaseEndMissingTestElement { + get { + return ResourceManager.GetString("DataCollectionTestCaseEndMissingTestElement", resourceCulture); + } + } + /// /// Looks up a localized string similar to Duplicate test extension URI '{0}'. Ignoring the duplicate extension.. /// diff --git a/src/Microsoft.TestPlatform.Common/Resources/Resources.resx b/src/Microsoft.TestPlatform.Common/Resources/Resources.resx index 0828045206..361dbacf8e 100644 --- a/src/Microsoft.TestPlatform.Common/Resources/Resources.resx +++ b/src/Microsoft.TestPlatform.Common/Resources/Resources.resx @@ -141,6 +141,15 @@ The data collector '{0}' requested environment variable '{1}' with value '{2}' to be set in test execution environment, but another data collector '{3}' has already requested same environment variable with different value '{4}'. + + The data collection environment context has not been initialized. Ensure that session started before processing test case events. + + + TestCaseStartEventArgs.TestElement is null. The data collector cannot start a test case without a test element. + + + TestCaseEndEventArgs.TestElement is null. The data collector cannot end a test case without a test element. + Duplicate test extension URI '{0}'. Ignoring the duplicate extension. diff --git a/src/Microsoft.TestPlatform.Common/Resources/xlf/Resources.cs.xlf b/src/Microsoft.TestPlatform.Common/Resources/xlf/Resources.cs.xlf index 4b59416829..164246974b 100644 --- a/src/Microsoft.TestPlatform.Common/Resources/xlf/Resources.cs.xlf +++ b/src/Microsoft.TestPlatform.Common/Resources/xlf/Resources.cs.xlf @@ -122,6 +122,21 @@ Nepovedlo se najít kolekci dat {0}. + + The data collection environment context has not been initialized. Ensure that session started before processing test case events. + The data collection environment context has not been initialized. Ensure that session started before processing test case events. + + + + TestCaseEndEventArgs.TestElement is null. The data collector cannot end a test case without a test element. + TestCaseEndEventArgs.TestElement is null. The data collector cannot end a test case without a test element. + + + + TestCaseStartEventArgs.TestElement is null. The data collector cannot start a test case without a test element. + TestCaseStartEventArgs.TestElement is null. The data collector cannot start a test case without a test element. + + The data collector '{0}' requested environment variable '{1}' with value '{2}' to be set in test execution environment, but another data collector '{3}' has already requested same environment variable with different value '{4}'. Kolekce dat {0} si v prostředí provedení testu vyžádala nastavení proměnné prostředí {1} na hodnotu {2}, ale jiná kolekce dat {3} si už vyžádala stejnou proměnnou prostředí s rozdílnou hodnotou {4}. diff --git a/src/Microsoft.TestPlatform.Common/Resources/xlf/Resources.de.xlf b/src/Microsoft.TestPlatform.Common/Resources/xlf/Resources.de.xlf index 3b0e0ee3a5..3b12403170 100644 --- a/src/Microsoft.TestPlatform.Common/Resources/xlf/Resources.de.xlf +++ b/src/Microsoft.TestPlatform.Common/Resources/xlf/Resources.de.xlf @@ -122,6 +122,21 @@ Datensammler "{0}" wurde nicht gefunden + + The data collection environment context has not been initialized. Ensure that session started before processing test case events. + The data collection environment context has not been initialized. Ensure that session started before processing test case events. + + + + TestCaseEndEventArgs.TestElement is null. The data collector cannot end a test case without a test element. + TestCaseEndEventArgs.TestElement is null. The data collector cannot end a test case without a test element. + + + + TestCaseStartEventArgs.TestElement is null. The data collector cannot start a test case without a test element. + TestCaseStartEventArgs.TestElement is null. The data collector cannot start a test case without a test element. + + The data collector '{0}' requested environment variable '{1}' with value '{2}' to be set in test execution environment, but another data collector '{3}' has already requested same environment variable with different value '{4}'. Der Datensammler "{0}" hat das Festlegen der Umgebungsvariablen "{1}" mit dem Wert "{2}" in der Testausführungsumgebung angefordert, ein anderer Datensammler "{3}" hat jedoch die gleiche Umgebungsvariable mit dem anderen Wert "{4}" angefordert. diff --git a/src/Microsoft.TestPlatform.Common/Resources/xlf/Resources.es.xlf b/src/Microsoft.TestPlatform.Common/Resources/xlf/Resources.es.xlf index c9f07356ae..e16221f3b8 100644 --- a/src/Microsoft.TestPlatform.Common/Resources/xlf/Resources.es.xlf +++ b/src/Microsoft.TestPlatform.Common/Resources/xlf/Resources.es.xlf @@ -122,6 +122,21 @@ No se pudo encontrar el recopilador de datos "{0}" + + The data collection environment context has not been initialized. Ensure that session started before processing test case events. + The data collection environment context has not been initialized. Ensure that session started before processing test case events. + + + + TestCaseEndEventArgs.TestElement is null. The data collector cannot end a test case without a test element. + TestCaseEndEventArgs.TestElement is null. The data collector cannot end a test case without a test element. + + + + TestCaseStartEventArgs.TestElement is null. The data collector cannot start a test case without a test element. + TestCaseStartEventArgs.TestElement is null. The data collector cannot start a test case without a test element. + + The data collector '{0}' requested environment variable '{1}' with value '{2}' to be set in test execution environment, but another data collector '{3}' has already requested same environment variable with different value '{4}'. El recopilador de datos "{0}" solicitó que la variable de entorno "{1}" con el valor "{2}" se estableciera en el entorno de ejecución de pruebas, pero otro recopilador de datos "{3}" ya ha solicitado la misma variable de entorno con otro valor "{4}". diff --git a/src/Microsoft.TestPlatform.Common/Resources/xlf/Resources.fr.xlf b/src/Microsoft.TestPlatform.Common/Resources/xlf/Resources.fr.xlf index 11ba039130..80ccb39f01 100644 --- a/src/Microsoft.TestPlatform.Common/Resources/xlf/Resources.fr.xlf +++ b/src/Microsoft.TestPlatform.Common/Resources/xlf/Resources.fr.xlf @@ -122,6 +122,21 @@ Collecteur de données '{0}' introuvable + + The data collection environment context has not been initialized. Ensure that session started before processing test case events. + The data collection environment context has not been initialized. Ensure that session started before processing test case events. + + + + TestCaseEndEventArgs.TestElement is null. The data collector cannot end a test case without a test element. + TestCaseEndEventArgs.TestElement is null. The data collector cannot end a test case without a test element. + + + + TestCaseStartEventArgs.TestElement is null. The data collector cannot start a test case without a test element. + TestCaseStartEventArgs.TestElement is null. The data collector cannot start a test case without a test element. + + The data collector '{0}' requested environment variable '{1}' with value '{2}' to be set in test execution environment, but another data collector '{3}' has already requested same environment variable with different value '{4}'. Le collecteur de données '{0}' exige que la variable d'environnement '{1}' avec la valeur '{2}' soit définie dans un environnement d'exécution de test, mais un autre collecteur de données '{3}' a déjà exigé la même variable d'environnement avec une autre valeur '{4}'. diff --git a/src/Microsoft.TestPlatform.Common/Resources/xlf/Resources.it.xlf b/src/Microsoft.TestPlatform.Common/Resources/xlf/Resources.it.xlf index 6aa82f4ec1..2c5e0874bf 100644 --- a/src/Microsoft.TestPlatform.Common/Resources/xlf/Resources.it.xlf +++ b/src/Microsoft.TestPlatform.Common/Resources/xlf/Resources.it.xlf @@ -122,6 +122,21 @@ L'agente di raccolta dati '{0}' non è stato trovato + + The data collection environment context has not been initialized. Ensure that session started before processing test case events. + The data collection environment context has not been initialized. Ensure that session started before processing test case events. + + + + TestCaseEndEventArgs.TestElement is null. The data collector cannot end a test case without a test element. + TestCaseEndEventArgs.TestElement is null. The data collector cannot end a test case without a test element. + + + + TestCaseStartEventArgs.TestElement is null. The data collector cannot start a test case without a test element. + TestCaseStartEventArgs.TestElement is null. The data collector cannot start a test case without a test element. + + The data collector '{0}' requested environment variable '{1}' with value '{2}' to be set in test execution environment, but another data collector '{3}' has already requested same environment variable with different value '{4}'. L'agente di raccolta dati '{0}' ha richiesto che la variabile di ambiente '{1}' con valore '{2}' fosse impostata nell'ambiente di esecuzione dei test, ma un altro agente di raccolta dati '{3}' ha già richiesto la stessa variabile di ambiente con un valore diverso '{4}'. diff --git a/src/Microsoft.TestPlatform.Common/Resources/xlf/Resources.ja.xlf b/src/Microsoft.TestPlatform.Common/Resources/xlf/Resources.ja.xlf index 3a22f8ad08..b2be321558 100644 --- a/src/Microsoft.TestPlatform.Common/Resources/xlf/Resources.ja.xlf +++ b/src/Microsoft.TestPlatform.Common/Resources/xlf/Resources.ja.xlf @@ -122,6 +122,21 @@ データ コレクター '{0}' が見つかりませんでした + + The data collection environment context has not been initialized. Ensure that session started before processing test case events. + The data collection environment context has not been initialized. Ensure that session started before processing test case events. + + + + TestCaseEndEventArgs.TestElement is null. The data collector cannot end a test case without a test element. + TestCaseEndEventArgs.TestElement is null. The data collector cannot end a test case without a test element. + + + + TestCaseStartEventArgs.TestElement is null. The data collector cannot start a test case without a test element. + TestCaseStartEventArgs.TestElement is null. The data collector cannot start a test case without a test element. + + The data collector '{0}' requested environment variable '{1}' with value '{2}' to be set in test execution environment, but another data collector '{3}' has already requested same environment variable with different value '{4}'. データ コレクター '{0}' が値 '{2}' の環境変数 '{1}' をテスト実行時環境で設定するように要求しましたが、別のデータ コレクター '{3}' が既に別の値 '{4}' を持つ同じ環境変数を要求しています。 diff --git a/src/Microsoft.TestPlatform.Common/Resources/xlf/Resources.ko.xlf b/src/Microsoft.TestPlatform.Common/Resources/xlf/Resources.ko.xlf index 37175efc69..83bfa34fe4 100644 --- a/src/Microsoft.TestPlatform.Common/Resources/xlf/Resources.ko.xlf +++ b/src/Microsoft.TestPlatform.Common/Resources/xlf/Resources.ko.xlf @@ -122,6 +122,21 @@ 데이터 수집기 '{0}'을(를) 찾을 수 없습니다. + + The data collection environment context has not been initialized. Ensure that session started before processing test case events. + The data collection environment context has not been initialized. Ensure that session started before processing test case events. + + + + TestCaseEndEventArgs.TestElement is null. The data collector cannot end a test case without a test element. + TestCaseEndEventArgs.TestElement is null. The data collector cannot end a test case without a test element. + + + + TestCaseStartEventArgs.TestElement is null. The data collector cannot start a test case without a test element. + TestCaseStartEventArgs.TestElement is null. The data collector cannot start a test case without a test element. + + The data collector '{0}' requested environment variable '{1}' with value '{2}' to be set in test execution environment, but another data collector '{3}' has already requested same environment variable with different value '{4}'. 데이터 수집기 '{0}'에서 값이 '{2}'인 환경 변수 '{1}'을(를) 테스트 실행 환경에서 설정하도록 요청했는데, 다른 데이터 수집기 '{3}'이(가) 다른 값('{4}')을 포함하는 동일 환경 변수를 이미 요청했습니다. diff --git a/src/Microsoft.TestPlatform.Common/Resources/xlf/Resources.pl.xlf b/src/Microsoft.TestPlatform.Common/Resources/xlf/Resources.pl.xlf index 10c5a716e5..f8d942902a 100644 --- a/src/Microsoft.TestPlatform.Common/Resources/xlf/Resources.pl.xlf +++ b/src/Microsoft.TestPlatform.Common/Resources/xlf/Resources.pl.xlf @@ -122,6 +122,21 @@ Nie można znaleźć modułu zbierającego dane „{0}” + + The data collection environment context has not been initialized. Ensure that session started before processing test case events. + The data collection environment context has not been initialized. Ensure that session started before processing test case events. + + + + TestCaseEndEventArgs.TestElement is null. The data collector cannot end a test case without a test element. + TestCaseEndEventArgs.TestElement is null. The data collector cannot end a test case without a test element. + + + + TestCaseStartEventArgs.TestElement is null. The data collector cannot start a test case without a test element. + TestCaseStartEventArgs.TestElement is null. The data collector cannot start a test case without a test element. + + The data collector '{0}' requested environment variable '{1}' with value '{2}' to be set in test execution environment, but another data collector '{3}' has already requested same environment variable with different value '{4}'. Moduł zbierający dane „{0}” zażądał ustawienia zmiennej środowiskowej „{1}” o wartości „{2}” w środowisku wykonywania testu, ale inny moduł zbierający dane „{3}” już zażądał ustawienia tej zmiennej środowiskowej na wartość „{4}”. diff --git a/src/Microsoft.TestPlatform.Common/Resources/xlf/Resources.pt-BR.xlf b/src/Microsoft.TestPlatform.Common/Resources/xlf/Resources.pt-BR.xlf index 5a543755e2..aa43ad390e 100644 --- a/src/Microsoft.TestPlatform.Common/Resources/xlf/Resources.pt-BR.xlf +++ b/src/Microsoft.TestPlatform.Common/Resources/xlf/Resources.pt-BR.xlf @@ -122,6 +122,21 @@ Não foi possível encontrar o coletor de dados '{0}' + + The data collection environment context has not been initialized. Ensure that session started before processing test case events. + The data collection environment context has not been initialized. Ensure that session started before processing test case events. + + + + TestCaseEndEventArgs.TestElement is null. The data collector cannot end a test case without a test element. + TestCaseEndEventArgs.TestElement is null. The data collector cannot end a test case without a test element. + + + + TestCaseStartEventArgs.TestElement is null. The data collector cannot start a test case without a test element. + TestCaseStartEventArgs.TestElement is null. The data collector cannot start a test case without a test element. + + The data collector '{0}' requested environment variable '{1}' with value '{2}' to be set in test execution environment, but another data collector '{3}' has already requested same environment variable with different value '{4}'. O coletor de dados '{0}' solicitou a variável de ambiente '{1}' com valor '{2}' para ser definida no ambiente de execução de teste, mas outro coletor de dados '{3}' já solicitou a mesma variável de ambiente com um valor diferente '{4}'. diff --git a/src/Microsoft.TestPlatform.Common/Resources/xlf/Resources.ru.xlf b/src/Microsoft.TestPlatform.Common/Resources/xlf/Resources.ru.xlf index f569087653..d78a1345f1 100644 --- a/src/Microsoft.TestPlatform.Common/Resources/xlf/Resources.ru.xlf +++ b/src/Microsoft.TestPlatform.Common/Resources/xlf/Resources.ru.xlf @@ -122,6 +122,21 @@ Не удалось найти сборщик данных "{0}" + + The data collection environment context has not been initialized. Ensure that session started before processing test case events. + The data collection environment context has not been initialized. Ensure that session started before processing test case events. + + + + TestCaseEndEventArgs.TestElement is null. The data collector cannot end a test case without a test element. + TestCaseEndEventArgs.TestElement is null. The data collector cannot end a test case without a test element. + + + + TestCaseStartEventArgs.TestElement is null. The data collector cannot start a test case without a test element. + TestCaseStartEventArgs.TestElement is null. The data collector cannot start a test case without a test element. + + The data collector '{0}' requested environment variable '{1}' with value '{2}' to be set in test execution environment, but another data collector '{3}' has already requested same environment variable with different value '{4}'. Сборщик данных "{0}" запросил, чтобы в окружении выполнения тестов была установлена переменная окружения "{1}" со значением "{2}", но другой сборщик данных "{3}" уже запросил эту переменную окружения со значением "{4}". diff --git a/src/Microsoft.TestPlatform.Common/Resources/xlf/Resources.tr.xlf b/src/Microsoft.TestPlatform.Common/Resources/xlf/Resources.tr.xlf index 6dba89fbd3..2a16de403a 100644 --- a/src/Microsoft.TestPlatform.Common/Resources/xlf/Resources.tr.xlf +++ b/src/Microsoft.TestPlatform.Common/Resources/xlf/Resources.tr.xlf @@ -122,6 +122,21 @@ '{0}' veri toplayıcısı bulunamadı + + The data collection environment context has not been initialized. Ensure that session started before processing test case events. + The data collection environment context has not been initialized. Ensure that session started before processing test case events. + + + + TestCaseEndEventArgs.TestElement is null. The data collector cannot end a test case without a test element. + TestCaseEndEventArgs.TestElement is null. The data collector cannot end a test case without a test element. + + + + TestCaseStartEventArgs.TestElement is null. The data collector cannot start a test case without a test element. + TestCaseStartEventArgs.TestElement is null. The data collector cannot start a test case without a test element. + + The data collector '{0}' requested environment variable '{1}' with value '{2}' to be set in test execution environment, but another data collector '{3}' has already requested same environment variable with different value '{4}'. '{0}' veri toplayıcısı, test yürütme ortamında değeri '{2}' olan '{1}' ortam değişkeninin ayarlanması için istekte bulundu, ancak başka bir veri toplayıcısı ('{3}') zaten farklı bir değerle ('{4}') aynı ortam değişkeni için istekte bulunmuştu. diff --git a/src/Microsoft.TestPlatform.Common/Resources/xlf/Resources.zh-Hans.xlf b/src/Microsoft.TestPlatform.Common/Resources/xlf/Resources.zh-Hans.xlf index e6a274da6d..da651e149b 100644 --- a/src/Microsoft.TestPlatform.Common/Resources/xlf/Resources.zh-Hans.xlf +++ b/src/Microsoft.TestPlatform.Common/Resources/xlf/Resources.zh-Hans.xlf @@ -122,6 +122,21 @@ 找不到数据收集器“{0}” + + The data collection environment context has not been initialized. Ensure that session started before processing test case events. + The data collection environment context has not been initialized. Ensure that session started before processing test case events. + + + + TestCaseEndEventArgs.TestElement is null. The data collector cannot end a test case without a test element. + TestCaseEndEventArgs.TestElement is null. The data collector cannot end a test case without a test element. + + + + TestCaseStartEventArgs.TestElement is null. The data collector cannot start a test case without a test element. + TestCaseStartEventArgs.TestElement is null. The data collector cannot start a test case without a test element. + + The data collector '{0}' requested environment variable '{1}' with value '{2}' to be set in test execution environment, but another data collector '{3}' has already requested same environment variable with different value '{4}'. 数据收集器“{0}”已请求具有将在测试执行环境中设置的值“{2}”的环境变量“{1}”,但另一个数据收集器“{3}”已请求具有其他值“{4}”的同一环境变量。 diff --git a/src/Microsoft.TestPlatform.Common/Resources/xlf/Resources.zh-Hant.xlf b/src/Microsoft.TestPlatform.Common/Resources/xlf/Resources.zh-Hant.xlf index b8b68c3ba4..de5cfdde8d 100644 --- a/src/Microsoft.TestPlatform.Common/Resources/xlf/Resources.zh-Hant.xlf +++ b/src/Microsoft.TestPlatform.Common/Resources/xlf/Resources.zh-Hant.xlf @@ -122,6 +122,21 @@ 找不到資料收集器 '{0}' + + The data collection environment context has not been initialized. Ensure that session started before processing test case events. + The data collection environment context has not been initialized. Ensure that session started before processing test case events. + + + + TestCaseEndEventArgs.TestElement is null. The data collector cannot end a test case without a test element. + TestCaseEndEventArgs.TestElement is null. The data collector cannot end a test case without a test element. + + + + TestCaseStartEventArgs.TestElement is null. The data collector cannot start a test case without a test element. + TestCaseStartEventArgs.TestElement is null. The data collector cannot start a test case without a test element. + + The data collector '{0}' requested environment variable '{1}' with value '{2}' to be set in test execution environment, but another data collector '{3}' has already requested same environment variable with different value '{4}'. 資料收集器 '{0}' 要求要在測試執行環境中將環境變數 '{1}' 的值設為 '{2}',但另一個資料收集器 '{3}' 已要求了同一個環境變數,但具有不同的值 '{4}'。 diff --git a/test/datacollector.UnitTests/DataCollectionManagerTests.cs b/test/datacollector.UnitTests/DataCollectionManagerTests.cs index ca6407d98e..dd74454997 100644 --- a/test/datacollector.UnitTests/DataCollectionManagerTests.cs +++ b/test/datacollector.UnitTests/DataCollectionManagerTests.cs @@ -469,6 +469,52 @@ public void TestCaseEndedShouldNotSendEventToDataCollectorIfDataCollectionIsNotE Assert.IsFalse(isEndInvoked); } + [TestMethod] + public void TestCaseStartedShouldThrowInvalidOperationExceptionWhenTestElementIsNull() + { + _dataCollectionManager.InitializeDataCollectors(_dataCollectorSettings); + var args = new TestCaseStartEventArgs(); // TestElement is null by default + Assert.ThrowsExactly(() => _dataCollectionManager.TestCaseStarted(args)); + } + + [TestMethod] + public void TestCaseEndedShouldThrowInvalidOperationExceptionWhenTestElementIsNull() + { + _dataCollectionManager.InitializeDataCollectors(_dataCollectorSettings); + var args = new TestCaseEndEventArgs(); + Assert.ThrowsExactly(() => _dataCollectionManager.TestCaseEnded(args)); + } + + [TestMethod] + public void TestCaseStartedShouldThrowInvalidOperationExceptionWhenContextNotInitialized() + { + // Do not call InitializeDataCollectors so _dataCollectionEnvironmentContext is null + SetupMockDataCollector((XmlElement a, DataCollectionEvents b, DataCollectionSink c, DataCollectionLogger d, DataCollectionEnvironmentContext e) => { }); + _dataCollectionManager.InitializeDataCollectors(_dataCollectorSettings); + + // Access internal state: force _dataCollectionEnvironmentContext to null by not running SessionStarted + // TestCaseStarted with a valid TestElement but no session context should throw + var fieldInfo = typeof(DataCollectionManager).GetField("_dataCollectionEnvironmentContext", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance); + fieldInfo!.SetValue(_dataCollectionManager, null); + + var args = new TestCaseStartEventArgs(new TestCase()); + Assert.ThrowsExactly(() => _dataCollectionManager.TestCaseStarted(args)); + } + + [TestMethod] + public void TestCaseEndedShouldThrowInvalidOperationExceptionWhenContextNotInitialized() + { + SetupMockDataCollector((XmlElement a, DataCollectionEvents b, DataCollectionSink c, DataCollectionLogger d, DataCollectionEnvironmentContext e) => { }); + _dataCollectionManager.InitializeDataCollectors(_dataCollectorSettings); + + var fieldInfo = typeof(DataCollectionManager).GetField("_dataCollectionEnvironmentContext", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance); + fieldInfo!.SetValue(_dataCollectionManager, null); + + var args = new TestCaseEndEventArgs(); + args.TestElement = new TestCase(); + Assert.ThrowsExactly(() => _dataCollectionManager.TestCaseEnded(args)); + } + private void SetupMockDataCollector(Action callback) { _mockDataCollector.Setup(