Create & Fake is a test support library, developed by humans, that makes robust testing easy by handling all manners of data generation, mocking, comparisons, validation and even automated requirement-based testing. Designed to handle the bulk of test setup quickly and easily so that developers can focus on the behavior to test, making tests easier to develop and maintain like so:
// Provided xUnit attributes used to automatically create the parameters. [Theory, RandomData] internal static void GetDirectors_UtilizesYearToPruneDirectors( [Fake] IStorage db, [Injected] Endpoint api, [Size(2)] Details[] movies) { // Setup fake behavior using randomized movie data (times optional). db.Find(movies[0].Name).SetupReturn(movies, Times.Once); // Call code and test for expected result (api is auto-injected with db fake). api.GetDirectors(movies[0].Name, movies[0].Year).Assert().Is(movies[0].Directors); // Optionally check all behavior called as expected. db.Assert().Called(); }
By default, all behavior works not by reference but by value even for complex objects. Smart randomization values are used for common parameter/property/field names like 'email', 'city' or 'animal'. Using the fluent extension methods and attributes are optional as all functionality are present in customizable tools:
[Fact] internal static void MailingAddress_VerifyChangingZipCodeUpdatesAddress() { // Randomizer uses readable values for some properties like 'FirstName'. User details = Tools.Randomizer.Create<User>(); // Duplicator creates deep clones. User copy = Tools.Duplicator.Copy(details); // Mutator can randomly modify objects too. details.ZipCode = Tools.Mutator.Variant(details.ZipCode); // Asserter performs checks based upon value. Tools.Asserter.IsNot(details.MailingAddress, copy.MailingAddress); }
Even more, classes are able to be automatically tested in a variety of ways simply by inheriting the automated test base:
public sealed class MyClassTests : AutoTester<MyClass>;
Create & Fake can even test entire assemblies and enforce quality throughout a project. No more nagging or having to remember every detail like adding a test class per code class; let the tests do the talking.
A key benefit of the library is in how the tools are logically integrated with each other. For example, the Randomizer will use stubs for interfaces that have no known implementations in the code. Or the mocks created by the Faker utilize value equality in matching arguments.
Asserter- Verify object states and behavior.Duplicator- Deep clone objects.Extractor- Flatten the contents of objects.Faker- Simulate behavior via stubs/mocks.Mutator- Modify the state of objects or create variants.Randomizer- Create objects populated with random values.Runner- Generate method data and run them.Tester- Test common scenarios.Valuer- Compare objects by value via reflection if needed.
Visit the documentation site for more information and how to get started.
A local site can be built from the source code using the terminal command "./build/run.sh serveDocs".
If you're looking to contribute, thanks for your interest. Feel free to submit reports for any issues you can find, or request potential features you'd like to see here. If you wish to contribute code to the project, refer to the contributing requirements and the support guide for environment setup. Please follow the code of conduct when contributing.
This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with this file, You can obtain one at https://mozilla.org/MPL/2.0/.
View the license file for more details.
- xUnit + NUnit + MSTest: For running tests.
- Coverlet + ReportGenerator + CodeCov: For test coverage.
- Bullseye + SimpleExec + MinVer: For project building.
- AsyncFixer + MissingAwaitWarning + Meziantou.Analyzer + Sonar: For code analyzers.
- DocFX + Mermaid: For building the documentation site.
- CSharpier: For formatting code.
- GitHub: For hosting code.
- Microsoft: For C# and editors.

