BlueDotBrigade.DatenLokator is a .NET NuGet package that streamlines automated testing by allowing you to load input data with a single line of code, thus reducing visual noise and improving test comprehension. This library supports multiple data formats, automatic decompression, global caching, and run-time customization.
- Retrieve data in different formats:
AsBytes()AsFile()AsString()AsStream()AsStreamReader()AsJson()
- Automatic decompression of
*.zipfiles.- Useful for saving disk space.
- Global cache support.
- Useful when multiple tests consume the same file as input.
- Run-time customization.
- Can be used to specify where the input data will be stored.
- Extensible library.
- Create extension methods to support custom target formats (e.g.
AsRecord()). - Implement the ITestNamingStrategy interface to support custom test naming conventions.
- Implement the IFileManagementStrategy interface for proprietary file management (e.g. cloud based storage).
- Create extension methods to support custom target formats (e.g.
Setup:
- Create a .NET automated test project.
- For example: Using Visual Studio add a MsTest Test Project to your solution.
- Daten Lokator will work with: MsTest, NUnit, XUnit, etc.
- Add the latest NuGet package to your test project:
- The Daten Lokator library must be initialized only once when the automated tests start.
- Example:
Lokator.Get().Setup() - If you are using MsTest then consider doing this where the
AssemblyInitializeattribute is used.
- Example:
- Create a
.Datenfolder within the project (*.csproj) directory.- Example:
/DemoTests/.Daten - Storing the input data within the project directory provides traceability, because now the input data can be committed to source control (e.g. GitHub).
- Example:
Test data sources and mock endpoints:
- Instances of
Datencan be used to load deterministic input fixtures from disk. Lokator.Register()can be used to setup lightweight sockets that serve static content — useful for testing HTTP clients without an external server.
Managing source files:
- Create an automated test.
- By default it is assumed that test method name follows the Assert Act Arrange naming convention.
- Save the input data in a file directory structure that mirrors the namespace.
- For example:
- Unit Tests:
/DemoTests/Serialization/XmlSerializerTests.cs - Input Data:
/DemoTests/.Daten/Serialization/XmlSerializerTests/*.*
- Unit Tests:
- Where:
.Datenis Daten Lokator's root directory for all input files.Serializationis the namespace where theXmlSerializerTests.csautomated tests can be found.
- For example:
- When an input file is needed, simply call the appropriate
Datenmethod from your automated test.- For example:
new Daten().AsString()
- For example:
The following unit tests, written for a trivial application, demonstrate how:
- easy it is to use Daten Lokator, and
- how the library reduces visual noise thus making the test easier to read