Skip to content

Commit

Permalink
Add information on tracing in adapter (#1016)
Browse files Browse the repository at this point in the history
* add information tracing in adapter

* auto-fix all linting errors

---------

Co-authored-by: Sean Killeen <[email protected]>
  • Loading branch information
OsirisTerje and SeanKilleen authored Feb 10, 2025
1 parent 013b956 commit 1a5e446
Show file tree
Hide file tree
Showing 3 changed files with 164 additions and 1 deletion.
20 changes: 19 additions & 1 deletion docs/articles/vs-test-adapter/Debugging.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,22 @@
# Debugging the NUnit3TestAdapter

## Enable Tracing

Before debugging the adapter, check the trace outputs, which can be enabled using runsettings, either from a file or
the command line.

Enable the following [features](https://docs.nunit.org/articles/vs-test-adapter/Tips-And-Tricks.html#dumpxmltestdiscovery-and-dumpxmltestresults):

```xml
<DumpXmlTestDiscovery>true</DumpXmlTestDiscovery>
<DumpXmlTestResults>true</DumpXmlTestResults>
```

This will create a Dump folder under the executing bin directory, containing one file for each setting. These files
include both the input from the testhost and the resulting data returned by the framework/engine.

## Enabling debugging

Debugging the adapter is done by first creating a debug version of the adapter.
You can then enable a debug run by passing one of the NUnit debug settings using runsettings.

Expand All @@ -19,7 +36,8 @@ From command line, you can set these by adding
dotnet test -- NUnit.DebugExecution=true
```

If you want to do this using Visual Studio, you must add a runsettings file, and add these settings there to the NUnit section.
If you want to do this using Visual Studio, you must add a runsettings file, and add these settings there to the NUnit
section.

A detailed explanation of the process can be found in [this blog post](https://hermit.no/debugging-the-nunit3testadapter-take-2/)

Expand Down
1 change: 1 addition & 0 deletions docs/snippets/Snippets.sln
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Snippets.NUnit", "Snippets.
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{6E5F0945-D524-45AB-AF2C-EFEB7B9CDB97}"
ProjectSection(SolutionItems) = preProject
naming.runsettings = naming.runsettings
nuget.config = nuget.config
EndProjectSection
EndProject
Expand Down
144 changes: 144 additions & 0 deletions docs/snippets/naming.runsettings
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- For more information, see https://docs.microsoft.com/en-us/visualstudio/test/configure-unit-tests-by-using-a-dot-runsettings-file?view=vs-2019 -->

<RunSettings>
<RunConfiguration>
<!-- See https://github.com/microsoft/vstest-docs/blob/master/docs/configure.md -->
<!-- 1. Test related settings -->
<!-- [x86] | x64: architecture of test host -->
<!--<TargetPlatform>x86</TargetPlatform>-->

<!-- Framework35 | [Framework40] | Framework45 -->
<!--<TargetFrameworkVersion>Framework40</TargetFrameworkVersion>-->

<!-- Path to Test Adapters -->
<!--<TestAdaptersPaths>%SystemDrive%\Temp\foo;%SystemDrive%\Temp\bar</TestAdaptersPaths>-->
<TreatTestAdapterErrorsAsWarnings>false</TreatTestAdapterErrorsAsWarnings>

<!-- Path relative to solution directory -->
<ResultsDirectory>.\TestResults</ResultsDirectory>

<!-- 0 = As many processes as possible, limited by number of cores on machine, 1 = Sequential (1 process), 2-> Given number of processes up to limit by number of cores on machine-->
<MaxCpuCount>0</MaxCpuCount>

<!-- TestSessionTimeout was introduced in Visual Studio 2017 version 15.5 -->
<!-- Specify timeout in milliseconds. A valid value should be >= 0. If 0, timeout will be infinity-->
<TestSessionTimeout>10000</TestSessionTimeout>

<!-- Specify a Boolean value, which defines the exit code when no tests are discovered.-->
<TreatNoTestsAsError>false</TreatNoTestsAsError>

<!-- STA | MTA default is STA for .NET Full and MTA for .NET Core-->
<!--<ExecutionThreadApartmentState>STA</ExecutionThreadApartmentState>-->

<!-- Disables in-assembly parallel execution, applies to both MSTest and NUnit -->
<DisableParallelization>false</DisableParallelization>
<DisableAppDomain>false</DisableAppDomain>
<CollectSourceInformation>true</CollectSourceInformation>

<!-- Runner related configuration -->
<BatchSize>10</BatchSize>

</RunConfiguration>

<!-- <DataCollectionRunSettings>
<DataCollectors> -->
<!-- This option can help you isolate a problematic test that causes a test host crash. Running the collector creates an output file (Sequence.xml) in TestResults, which captures the order of execution of the test before the crash. -->
<!-- See https://docs.microsoft.com/en-us/visualstudio/test/configure-unit-tests-by-using-a-dot-runsettings-file?view=vs-2022#blame-data-collector-->
<!-- <DataCollector friendlyName="blame" enabled="True">
</DataCollectors> -->
<!-- </DataCollectionRunSettings> -->

<!--
<TestRunParameters>
<Parameter name="webAppUrl" value="http://localhost" />
<Parameter name="webAppUserName" value="Admin" />
</TestRunParameters> -->

<!-- Section for loggers, see https://docs.microsoft.com/en-us/visualstudio/test/configure-unit-tests-by-using-a-dot-runsettings-file?view=vs-2019#loggerrunsettings-element
<LoggerRunSettings>
<Loggers>
<Logger friendlyName="console" enabled="True">
<Configuration>
<Verbosity>quiet</Verbosity>
</Configuration>
</Logger>
<Logger friendlyName="trx" enabled="True">
<Configuration>
<LogFileName>foo.trx</LogFileName>
</Configuration>
</Logger>
<Logger friendlyName="html" enabled="True">
<Configuration>
<LogFileName>foo.html</LogFileName>
</Configuration>
</Logger>
</Loggers>
</LoggerRunSettings>
-->


<!-- Adapter Specific sections -->

<!-- MSTest adapter -->
<MSTest>
<MapInconclusiveToFailed>false</MapInconclusiveToFailed>
<CaptureTraceOutput>true</CaptureTraceOutput>
<DeleteDeploymentDirectoryAfterTestRunIsComplete>true</DeleteDeploymentDirectoryAfterTestRunIsComplete>
<DeploymentEnabled>true</DeploymentEnabled>
<DeployTestSourceDependencies>true</DeployTestSourceDependencies>
<MapNotRunnableToFailed>false</MapNotRunnableToFailed>
<EnableBaseClassTestMethodsFromOtherAssemblies>false</EnableBaseClassTestMethodsFromOtherAssemblies>
<!-- <TestTimeout>5000</TestTimeout> -->

<!-- Uncomment and update path for assembly resolution -->
<!-- <AssemblyResolution>
<Directory path="D:\myfolder\bin\" includeSubDirectories="false"/>
</AssemblyResolution> -->
<ForcedLegacyMode>false</ForcedLegacyMode>
<!--
<SettingsFile>a .testsettings file (require ForcedLegacyMode true) </SettingsFile>
-->
</MSTest>

<!-- NUnit3 adapter, uncomment sections to set as appropriate, numeric, booleans, enums have their default values below, except RandomSeed -->
<!-- For documentation, see https://docs.nunit.org/articles/vs-test-adapter/Tips-And-Tricks.html -->
<NUnit>
<!--<BasePath>D:\Dev\NUnit\nunit3-vs-adapter\demo\NUnitTestDemo\bin\Release</BasePath>-->
<!--<PrivateBinPath>extras;more.extras</PrivateBinPath>-->
<DefaultTimeout>0</DefaultTimeout>
<!--<WorkDirectory>work</WorkDirectory>-->
<InternalTraceLevel>Off</InternalTraceLevel>
<!--<RandomSeed>1234567</RandomSeed>-->
<NumberOfTestWorkers>-1</NumberOfTestWorkers>
<Verbosity>0</Verbosity>
<!--<UseVsKeepEngineRunning>false</UseVsKeepEngineRunning>-->
<!--<ShadowCopyFiles>false</ShadowCopyFiles>-->
<DefaultTestNamePattern>{m}</DefaultTestNamePattern>
<!--<DomainUsage>Single</DomainUsage>-->
<DumpXmlTestDiscovery>false</DumpXmlTestDiscovery>
<DumpXmlTestResults>true</DumpXmlTestResults>
<ShowInternalProperties>false</ShowInternalProperties>
<!--<TestOutputXml>TestOutputXml</TestOutputXml>-->
<!--<Where></Where>-->
<!-- NUnit filter expression, see https://docs.nunit.org/articles/nunit/running-tests/Test-Selection-Language.html -->
<ConsoleOut>1</ConsoleOut>
<UseTestNameInConsoleOutput>true</UseTestNameInConsoleOutput>
<StopOnError>false</StopOnError>
<SkipNonTestAssemblies>false</SkipNonTestAssemblies>
<MapWarningTo>Skipped</MapWarningTo>
<!--Passed, Failed or Skipped-->
<DisplayName>Name</DisplayName>
<!--Name, FullName or FullNameSep-->
<FullnameSeparator>:</FullnameSeparator>
<DiscoveryMethod>Current</DiscoveryMethod>
<!--Legacy or Current-->
<AssemblySelectLimit>2000</AssemblySelectLimit>
<NewOutputXmlFileForEachRun>false</NewOutputXmlFileForEachRun>
<IncludeStackTraceForSuites>true</IncludeStackTraceForSuites>
<ExplicitMode>Strict</ExplicitMode>
<SkipExecutionWhenNoTests>false</SkipExecutionWhenNoTests>

</NUnit>
</RunSettings>

0 comments on commit 1a5e446

Please sign in to comment.