Skip to content

Getting Started ​

What is Skugga? ​

Skugga (Swedish for Shadow) is a mocking library engineered specifically for Native AOT and Cloud-Native .NET. It moves mocking logic from runtime reflection to compile-time code generation, so the common path has no dynamic proxies and no JIT dependency. Runtime fallbacks remain for cases the generator has not covered; see Native AOT support for exactly what is and is not AOT-clean.

Legacy tools like Moq rely on System.Reflection.Emit to generate proxy objects at runtime. Since Native AOT strips away the JIT compiler, these tools crash instantly. Skugga eliminates this trade-off by generating mock implementations during the build process.

Installation ​

1. Install Skugga ​

bash
dotnet add package Skugga

Requirements

  • .NET 8.0 or later
  • C# 12 enabled (LangVersion 12 or latest)

No Manual Configuration Needed

The Skugga NuGet package automatically configures C# Interceptors via its bundled .targets file. No manual .csproj changes are required.

Writing Your First Test ​

csharp
using Skugga.Core;

public interface IEmailService
{
   string GetEmailAddress(int userId);
   string TenantName { get; }
}

public class MyFirstTest
{
   public void Run()
   {
       // 1. Create the mock (intercepted at compile time)
       var mock = Mock.Create<IEmailService>();

       // 2. Configure behavior
       mock.Setup(x => x.GetEmailAddress(1)).Returns("digvijay@digvijay.dev");
       mock.Setup(x => x.TenantName).Returns("Contoso");

       // 3. Execute
       var email = mock.GetEmailAddress(1); // Returns "digvijay@digvijay.dev"
       var tenant = mock.TenantName;        // Returns "Contoso"
   }
}

How It Works ​

Skugga leverages C# 12 Interceptors to seamlessly rewire your code during compilation:

  1. Scan -- The Source Generator detects calls to Mock.Create<T>().
  2. Generate -- It writes a concrete, optimized C# class (Skugga_T) that implements T.
  3. Intercept -- The compiler replaces your Mock.Create call with new Skugga_T().

Zero Friction: To the developer, it looks like a normal method call. To the runtime, it looks like hand-written, optimized code.

Next Steps ​

Released under the MIT License.