TestSurface 1.0.1

There is a newer version of this package available.
See the version list below for details.
dotnet add package TestSurface --version 1.0.1
                    
NuGet\Install-Package TestSurface -Version 1.0.1
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="TestSurface" Version="1.0.1" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="TestSurface" Version="1.0.1" />
                    
Directory.Packages.props
<PackageReference Include="TestSurface" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add TestSurface --version 1.0.1
                    
#r "nuget: TestSurface, 1.0.1"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package TestSurface@1.0.1
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=TestSurface&version=1.0.1
                    
Install as a Cake Addin
#tool nuget:?package=TestSurface&version=1.0.1
                    
Install as a Cake Tool

Test Surface

v1.0

Description

The lib defines a testing contract, provides a command line arguments parser, a simple printing utility and a test runner. In order to use the runner one has to implement the ITestSurface interface:

public interface ITestSurface
{
	string Info { get; }
	string FailureMessage { get; }
	bool? Passed { get; }
	bool IsComplete { get; }
	bool IndependentLaunchOnly { get; }
	Task Run(ArgMap args);
}

The runner can be launched in two modes:

  • with a specific test class and arguments, by passing a -TheTestClassName as a command line parameter
  • with -all to discover all the compatible classes and invoke their Run method. Tests having IndependentLaunchOnly = true will be ignored as they cannot be fed with specific data because that could brake the rest of the tests.

The ArgMap type is an IDictionary<string, List<string>> instance, produced by the ArgsParser. Inside the Run method each test is provided with a copy of the original dictionary, so that common test paths could be reused by adding arguments.

The IDictionary<string, List<string>> holds the switches as keys with the dash (e.g. -all) and a list of string arguments provided in the console after the switch.

Additional arguments:

  • including -info will take the Info property and trace it instead of executing the Run method.
  • with -notrace all Print.AsInfo(), Print.Trace() invocations will be ignored
  • use -brake to stop the test launcher on the first failure

Launching with -all -info will trace all test descriptions.

Use Print to trace info during the test instead of Console directly for it can be suppressed with -notrace and also the Print.Trace() method has a lock for correct coloring in multi-threaded code.

Usage

Add a reference to the TestRunner.dll and implement the ITestSurface interface:

public class TestCase : ITestSurface
{
	public string Info => "Test description...";

	public string FailureMessage { get; private set; }
	public bool? Passed { get; private set; }
	public bool IndependentLaunchOnly => false;
	public bool IsComplete { get; private set; }

	public async Task Run(IDictionary<string, List<string>> args)
	{
		if (args.ContainsKey("-all"))
			// add default switches 
			args.Add("-whatever", new List<string>() { "10", "1000" });

		// The common path, i.e. either -all or -TestCase
		var w = args["-whatever"];

		// ...

		if (!Passed.HasValue) Passed = true;
		IsComplete = true;
	}
}

Launch a new Runner instance:

using System;
using TestSurface;

namespace Tests
{
	class Program
	{
		static void Main(string[] args)
		{
			// The args should contain -all or -ClassName
			new Runner().Run(args);

			// Await
			Print.AsSystemTrace("Done. Press <Enter> to close.");
			Console.ReadLine();

			// Or return 0;
		}
	}
}
Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • .NETStandard 2.0

    • No dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.3.0 676 7/13/2020
1.2.0 702 6/28/2019
1.1.4 617 6/17/2019
1.1.3 661 3/21/2019
1.1.2 642 3/21/2019
1.1.1 654 3/5/2019
1.1.0 652 2/25/2019
1.0.6 671 2/21/2019
1.0.5 733 2/20/2019
1.0.4 719 2/19/2019
1.0.3 741 2/14/2019
1.0.2 730 1/25/2019
1.0.1 706 1/25/2019
1.0.0 791 1/1/2019