I recently made several updates to the xunit.extensions.config library, which allows you to configure theory data from your app.config file. Here are the links to the source and the NuGet package:
New Features
- Named Parameter Support
You no longer need to configure your data by parameter index. You can now name your data for each parameter, making the configuration much easier to read and understand.
- AppSettings Support
You can now use the standard AppSettings section of the App.config to configure your data. If no settings are found, then the framework will fallback to trying to use the standard config section.
- Default Namespace Option
You can now provide a default namespace for your tests. This reduced the amount of redundant text in your config file, and makes test names much more concise and easy to read.
- Extensible Data Provider
Don't want to use the existing data providers? Would you rather use a database? Now you can! Just add an AppSettings key for "TestData.ServiceFactory" that provides the fully qualified name of a static method that returns an IConfigTestDataService, and the framework will try to use that to load configuration data.
Sample App.config
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<appSettings>
<add key="TestData.DefaultNamespace" value="Xunit.Extensions.Config.Tests2" />
<add key="TestData[0].Name" value="SampleTest.FromConfig" />
<add key="TestData[0].Data[0][Name]" value="Linq" />
<add key="TestData[0].Data[0][Age]" value="7" />
<add key="TestData[0].Data[0][IsFriendly]" value="true" />
</appSettings>
</configuration>
Sample Unit Test
namespace Xunit.Extensions.Config.Tests2
{
public class SampleTest
{
[Theory]
[ConfigOrInlineData("Taboo", 5, false)]
public void FromConfig(string name, int age, bool isFriendly)
{
Assert.Equal("Linq", name);
Assert.Equal(7, age);
Assert.Equal(true, isFriendly);
}
}
}
Enjoy,
Tom
No comments:
Post a Comment