This is an open source, .NET Standard 1.3 library that provides the abstract base class foundations for automated testing - designed to make it easier to implement test cases and to read their output.
Below are the main features of the library. See the linked code for details.
Please contact me if you have any questions.
NuGet Package Installation
To install the ChannelAdam.TestFramework NuGet package run the following command in the Package Manager Console:
1PM> Install-Package ChannelAdam.TestFramework
This library is intended for use by other Test Framework implementation libraries that are then to be used by application developers, such as:
- ChannelAdam Test Framework Moq Library
- ChannelAdam Test Framework MSTest Library
- ChannelAdam Test Framework MSTest V2 Library
- ChannelAdam Test Framework NUnit Library
Logging useful information to the output of a test is extremely important.
- Simple Console Logger implementation is a thin wrapper around
Log and then Assert
I cannot emphasise enough how important it is to log useful to the output of a test. Developers and analysts almost should be able to read the output of a test like a story. Analysts especially should review the test outputs and be satisfied that the test was implemented correctly - almost as if they performed the test themselves. Therefore, when an assertion is performed, we want the test output to actually tell us that an assertion is taking place and provide a information about what is being asserted.
The Log Asserter interface provides all the usual assertion methods that you are familiar with, and the first parameter of all of the methods is a string
that will be outputted to an
ISimpleLogger (provided in the constructor) before performing the actual assertion. This string is intended to provide the reader of the test output with a human-readable description of what is being asserted, often times just the name of the field/property being asserted, or something more descriptive for say an
Test Easy Base Class for Tests
Logging, assertions and testing for exceptions are 3 of some fundamental features common to most automated test suites. Wouldn’t it be nice to be able to perform that functionality easily and keep your test code to a minimum?
The TestEasy base class for tests provides those abilities.
This class provides the following helpful properties.
ISimpleLogger Logger- for logging to the test output
ILogAsserter LogAssert- your handy-dandy log asserter
ExpectedExceptionDescriptor ExpectedException- describes the exception that is expected to occur for a specific test case
Exception ActualException- for storing the actual exception that occurred
ActualException property is set, the details are automatically logged to the test output.
TestEasy also contains the following helpful methods:
void Try(Action action)- performs the given action and catches exceptions into
void Try(Func<Task> action)- performs the given asynchronous action that returns a Task, waits for it finish, and catches exceptions into
void AssertNoExceptionOccurred()- asserts that no
void AssertExpectedException(Type expectedExceptionType)- asserts that type of the value of
ActualExceptionis the given expected type
void AssertExpectedException()- asserts that the
ActualExceptionis equivalent to that described by the
ActualException is an
System.AggregateException, the assertion will pass if there is at least one inner exception equivalent to the
Expected Exception Descriptor
ExpectedException property is implemented by the
This class describes the exception that is expected to occur.
There are 2 properties in
ExpectedExceptionDescriptor that are specifically used in the
string MessageShouldContainText- which describes the substring that the
ActualException.Messageproperty should contain
Type ExpectedType- which describes the
Either or both of these properties can be set. When set, the details are automatically logged to the test output.