Applying a .runsettings file from the command line in .NET Core

Applying a .runsettings file from the command line in .NET Core

This entry is part 8 of 9 in the series Launching WebDrivers in .NET Core the easy way

As discussed last time, using Visual Studio as an IDE, it is simple to apply configuration from a .runsettings file. Unfortunately, as Visual Studio is not cross platform, using them in cross platform testing is not so easy.

I have tried and failed to apply settings in JetBrains Rider. If you do work out how to do so, please do let me know!

That leaves me with testing from the command line. This is covered in the documentation for .runsettings, but there is a significant gotcha waiting for the unprepared, hence this post to remind myself when I get stuck again.

The problem

How to apply a .runsettings file to a test run from the command line.

Unfortunately, using ./{relative_path} doesn’t work, you actually need to provide the full path to the runsettings file you wish to apply. Adding to the frustration, although path completion using the TAB key also works in powershell while typing out the command, it is not supported in the bash shell that you are probably using on MacOS and Linux.

You can reduce your typing a little using the ~/ shortcut to get to your

The solution

MacOS

Solution in /home/RiderProjects/

dotnet test NetCoreWebDriverFactoryDevelopment.sln --no-build --settings ~/RiderProjects/NetCoreWebDriverFactory/src/Test/AlexanderOnTest.NetCoreWebDriverFactory.UnitTests/Settings/UseReal.runsettings

Linux

Solution in /home/src/

dotnet test NetCoreWebDriverFactoryDevelopment.sln --no-build --settings ~/src/NetCoreWebDriverFactory/src/Test/AlexanderOnTest.NetCoreWebDriverFactory.UnitTests/Settings/UseReal.runsettings

Windows

Solution in C:\src

dotnet test --no-build -Settings C:\src\NetCoreWebDriverFactory\src\Test\AlexanderOnTest.NetCoreWebDriverFactory.UnitTests\Settings\UseFakes.runsettings

In Summary

Progress made:

  • Running tests using .runsettings files in different OSes.
  • Understanding the differences between platforms.

Lessons learnt:

  • Although the dotnet command has the same syntax on Bash and PowerShell, do not expect them to behave exactly the same, particularly around referencing files.
  • When referencing the .runsettings file in Bash (Mac and Linux), you cannot use ./ to reference the current directory, but ~/ for the user home directory does work.

A reminder:

If you want to ask me a question, Twitter is undoubtedly the fastest place to get a response: My Username is @AlexanderOnTest so I am easy to find. My DMs are always open for questions, and I publicise my new blog posts there too.

[Edit 26/6/19 Moved into the new series: Launching WebDrivers in .NET Core the easy way]

Series Navigation<< Test Configuration with .NET Core and NUnit 3Dependency Injection the .NET Core way >>
Comments are closed.