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
dotnet add package SkuggaRequirements
- .NET 8.0 or later
- C# 12 enabled (LangVersion
12orlatest)
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
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:
- Scan -- The Source Generator detects calls to
Mock.Create<T>(). - Generate -- It writes a concrete, optimized C# class (
Skugga_T) that implementsT. - Intercept -- The compiler replaces your
Mock.Createcall withnew 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
- Mock Creation -- Explore all ways to create mocks
- Setup & Returns -- Configure mock behavior
- Verification -- Assert method calls happened
- Migrating from Moq -- Seamless migration guide
- Architecture -- Deep dive into how Skugga works