All Projects → akamud → FakeItEasy.AutoFakeIt

akamud / FakeItEasy.AutoFakeIt

Licence: MIT license
A very simple, yet flexible, "AutoFaker" for FakeItEasy to easily auto generate classes with faked dependencies.

Programming Languages

C#
18002 projects

Projects that are alternatives of or similar to FakeItEasy.AutoFakeIt

bUnit
bUnit is a testing library for Blazor components that make tests look, feel, and runs like regular unit tests. bUnit makes it easy to render and control a component under test’s life-cycle, pass parameter and inject services into it, trigger event handlers, and verify the rendered markup from the component using a built-in semantic HTML comparer.
Stars: ✭ 857 (+5613.33%)
Mutual labels:  unit-testing, xunit, nunit, mstest
Specflow
#1 .NET BDD Framework. SpecFlow automates your testing & works with your existing code. Find Bugs before they happen. Behavior Driven Development helps developers, testers, and business representatives to get a better understanding of their collaboration
Stars: ✭ 1,827 (+12080%)
Mutual labels:  xunit, nunit, mstest
Cake
🍰 Cake (C# Make) is a cross platform build automation system.
Stars: ✭ 3,154 (+20926.67%)
Mutual labels:  unit-testing, xunit, nunit
Fluentassertions
A very extensive set of extension methods that allow you to more naturally specify the expected outcome of a TDD or BDD-style unit tests. Targets .NET Framework 4.7, .NET Core 2.1 and 3.0, as well as .NET Standard 2.0 and 2.1. Supports the unit test frameworks MSTest2, NUnit3, XUnit2, MSpec, and NSpec3.
Stars: ✭ 2,449 (+16226.67%)
Mutual labels:  unit-testing, xunit, mstest
kekiri
A .NET framework that supports writing low-ceremony BDD tests using Gherkin language
Stars: ✭ 19 (+26.67%)
Mutual labels:  xunit, nunit
testcontainers-dotnet
dotnet port of testcontainers-java
Stars: ✭ 22 (+46.67%)
Mutual labels:  xunit, nunit
Xunit
xUnit.net is a free, open source, community-focused unit testing tool for the .NET Framework.
Stars: ✭ 3,120 (+20700%)
Mutual labels:  unit-testing, xunit
Bunit
A testing library for Blazor Components. You can easily define components under test in C# or Razor syntax and verify outcome using semantic HTML diffing/comparison logic. You can easily interact with and inspect components, trigger event handlers, provide cascading values, inject services, mock IJSRuntime, and perform snapshot testing.
Stars: ✭ 415 (+2666.67%)
Mutual labels:  unit-testing, nunit
Nunit cshaprp cheatsheet
Example implementations of each attribute available in Nunit2 unit Testing Framework using C# .NET.
Stars: ✭ 14 (-6.67%)
Mutual labels:  unit-testing, nunit
Aspnetcore Tests Sample
A project to help demonstrate how to do unit, integration and acceptance tests with an web api project using ASP.NET Core and Angular 7 front end.
Stars: ✭ 40 (+166.67%)
Mutual labels:  unit-testing, nunit
MinimalApi
ASP.NET Core 7.0 - Minimal API Example - Todo API implementation using ASP.NET Core Minimal API, Entity Framework Core, Token authentication, Versioning, Unit Testing, Integration Testing and Open API.
Stars: ✭ 156 (+940%)
Mutual labels:  unit-testing, xunit
bitrix-module-bunit
BUnit - фреймворк модульного тестрования для CMS Bitrix
Stars: ✭ 20 (+33.33%)
Mutual labels:  unit-testing, xunit
kmtest
Kernel-mode C++ unit testing framework in BDD-style
Stars: ✭ 42 (+180%)
Mutual labels:  unit-testing
tink unittest
Tinkerbell Unit Testing
Stars: ✭ 15 (+0%)
Mutual labels:  unit-testing
eat
Json based scenario testing tool(which can have test for functional and non-functional)
Stars: ✭ 41 (+173.33%)
Mutual labels:  unit-testing
picolisp-unit
Unit Testing framework for PicoLisp
Stars: ✭ 22 (+46.67%)
Mutual labels:  unit-testing
currency-api
A demo project on how to test a node/express app with Mocha, Nock and proxyquire (MNP) and code coverage with nyc/istanbul.
Stars: ✭ 19 (+26.67%)
Mutual labels:  unit-testing
floss
Unit-testing for those hard to reach places
Stars: ✭ 26 (+73.33%)
Mutual labels:  unit-testing
Caraya
Assertion and unit test framework for LabVIEW
Stars: ✭ 45 (+200%)
Mutual labels:  unit-testing
wab-test-example
ESRI Web App Builder Widget built using a wrapped widget convention and containing unit tests. This widget is meant to be used as an example to demonstrate the two techniques.
Stars: ✭ 21 (+40%)
Mutual labels:  unit-testing

FakeItEasy.AutoFakeIt

Build codecov Nuget

A very simple, yet flexible, "AutoFaker" for FakeItEasy to easily auto generate classes with faked dependencies.

Getting started

NuGet package available:

PM> Install-Package FakeItEasy.AutoFakeIt

I focused on providing a familiar and very simple-to-use API, without any unnecessary limitations, so you can automatically generate your System Under Test (SUT) with all the dependencies faked, whether they are classes or interfaces. You can also customize and retrieve any dependency you want.

using FakeItEasy;
using FakeItEasy.AutoFakeIt;
using NUnit.Framework;

namespace UnitTests
{
    public interface IMyDependency
    {
        string MyMethod();
    }

    public class MyDependency : IMyDependency
    {
        public string MyMethod() => "Hello";
    }

    public class MyOtherDependency
    {
        public virtual string MyMethod() => "World";
    }

    public class MySut
    {
        public IMyDependency MyDependency { get; }
        public MyOtherDependency MyOtherDependency { get; }

        public MySut(IMyDependency myDependency, MyOtherDependency myOtherDependency)
        {
            MyDependency = myDependency;
            MyOtherDependency = myOtherDependency;
        }
    }

    public class SampleTest
    {
        [Test]
        public void MyTest()
        {
            // the main entrypoint, you can put this on a base class, as long
            // as you always create a new one for each test to make sure that
            // your tests are idempotent and isolated
            var autoFakeIt = new AutoFakeIt();

            // you can optionally provide a dependency for any type
            autoFakeIt.Provide<IMyDependency>(new MyDependency());

            // it will respect any objects you've provided before
            // you can also just let the Generate provide FakeItEasy's fakes
            // for all missing dependencies
            var mySut = autoFakeIt.Generate<MySut>();

            // you can get any dependency used/generated
            var theAutoFakedDependency = autoFakeIt.Resolve<MyOtherDependency>();

            // you can setup or assert the generated fakes since it is
            // just an ordinary FakeItEasy's fake object
            A.CallTo(() => theAutoFakedDependency.MyMethod()).Returns("Faked");
        }
    }
}

That's all you probably need from an autofaker. If you want, you can look at this project's tests to see all the possibilites.

Other options

There are many other alternatives to this package, why did I make yet another autofaker for FakeItEasy? While all the other alternatives worked, many of them had a few shortcomings related to how I expected it to work. I grew accustomed to the automocker from Moq that had a very similar API to this package.
That doesn't mean that this is the best implementation available, it just means that this is the implementation that was the most familiar to me. Hopefully some of you will find it familiar too.

My goal with this package was to provide all the features I wanted, that were missing in all the other alternatives I've tested:

  • Have a way of providing a concrete class instead of relying on a faked dependency
  • Automatically provide a fake for a concrete class (with virtual methods) instead of requiring an interface
  • Allow changing a dependency after instantiating the AutoFakeIt object
  • Allow passing dependencies or requesting generated dependencies any time

All the other packages missed some of the above.

Available alternatives

Contributing

If you have a scenario that isn't supported, please open an issue so we can discuss it :)

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].