Skip to main content

mocklis by Esbjörn Redmo

Nuget / site data

Nuget GitHub last commit GitHub Repo stars

Details

Info

info

Name: mocklis

Mocklis is a library and source code generator for .net, targeted at generating test doubles from interfaces. This package contains tools for writing tests using the generated code.

Author: Esbjörn Redmo

NuGet: https://www.nuget.org/packages/mocklis/

You can find more details at https://mocklis.readthedocs.io/en/latest/getting-started/index.html

Source : https://github.com/mocklis/mocklis/

Original Readme

note

Mocklis is a library and source code generator for .net, targeted at generating test doubles from interfaces.


Home page: https://mocklis.net

Github project page: https://github.com/mocklis

Documentation: https://mocklis.readthedocs.io

NuGet page: https://www.nuget.org/profiles/mocklis

About

note

Generating mocks from classes for unit tests

How to use

Example ( source csproj, source files )

This is the CSharp Project that references mocklis

<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>

<IsPackable>false</IsPackable>
<IsTestProject>true</IsTestProject>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.9.0-preview-23577-04" />
<PackageReference Include="Mocklis" Version="1.4.0-alpha.2" />
<PackageReference Include="MSTest.TestAdapter" Version="3.2.0-preview.23623.1" />
<PackageReference Include="MSTest.TestFramework" Version="3.2.0-preview.23623.1" />
<PackageReference Include="coverlet.collector" Version="6.0.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\MockLisClock\MockLisClock.csproj" />
</ItemGroup>
<PropertyGroup>
<EmitCompilerGeneratedFiles>true</EmitCompilerGeneratedFiles>
<CompilerGeneratedFilesOutputPath>$(BaseIntermediateOutputPath)\GX</CompilerGeneratedFilesOutputPath>
</PropertyGroup>

</Project>

Generated Files

Those are taken from $(BaseIntermediateOutputPath)\GX

// <auto-generated />

#nullable enable

namespace TestClock
{
partial class TestMock
{
public global::Mocklis.Core.FuncMethodMock<global::System.DateTime> GetNow { get; }

global::System.DateTime global::MockTest.IMyClock.GetNow() => GetNow.Call();

public global::Mocklis.Core.FuncMethodMock<global::System.DateTime> GetUtcNow { get; }

global::System.DateTime global::MockTest.IMyClock.GetUtcNow() => GetUtcNow.Call();

public TestMock() : base()
{
this.GetNow = new global::Mocklis.Core.FuncMethodMock<global::System.DateTime>(this, "TestMock", "IMyClock", "GetNow", "GetNow", global::Mocklis.Core.Strictness.Lenient);
this.GetUtcNow = new global::Mocklis.Core.FuncMethodMock<global::System.DateTime>(this, "TestMock", "IMyClock", "GetUtcNow", "GetUtcNow", global::Mocklis.Core.Strictness.Lenient);
}
}
}

Usefull

Download Example (.NET C# )

Share mocklis

https://ignatandrei.github.io/RSCG_Examples/v2/docs/mocklis

In the same category (Tests) - 3 other generators

MSTest

Ridge

Rocks