App.config for Xunit

I am writing several xUnit tests for some helper classes that rely on some configuration parameters, usually stored in the App.config or on the Internet .config of the executable project.

The configuration looks like this:

<?xml version="1.0" encoding="utf-8" ?> <configuration> <appSettings> <add key="FileNamePattern" value="\\d{8}_\\w{4:20}\.png"/> <!-- and the likes --> </appSettings> </configuration> 

I am running xUnit 1.9 with the GUI runner (xunit.gui.clr4.exe) and the xUnit console console (on the Jenkins CI server). Currently, I can โ€œenterโ€ these configuration values โ€‹โ€‹into test environments by manually installing xunit.gui.clr4.exe.config and xunit.console.exe.config); however it is tiring and error prone.

I could also make fun of these configuration parameters in the instrument. But using the same device in 10 different files is pretty repeated.

Is there a better way to trick these configuration options with xUnit, for example, provide an App.config file for a test project?

+7
source share
1 answer

If your code assumes that it is in app.config , then xUnit.net supports posting them there by providing one (usually when the tests are in a DLL file, this means that you get the AssemblyName.dll.config file in the project outputs, which the runner loads as settings, if it exists at boot time).

Obviously, there is no harm in using the DI principle to eliminate such dependencies in the first place, but I would say do not mix up the code before you try it first.

To save DRY, place app.config in the center and add it as a link (via the arrow on the Open button in the dialog box). (Yes, I really donโ€™t like it there - use it only if you feel its least evil approach.)


One thing to note is that changes are not loaded into the GUI runner unless you ask to reload the assembly.

+10
source

All Articles