Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/dotnet-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
- name: Setup .NET
uses: actions/setup-dotnet@v6
with:
dotnet-version: 9.x
dotnet-version: 10.x

- name: Linting
run: dotnet format --verify-no-changes
Expand Down
8 changes: 5 additions & 3 deletions docs/docs/operator/contribution/running-sdk-tests.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,11 @@ of your **current kubeconfig context**. Only run them against a disposable devel
dotnet test

# Run tests for a specific project
dotnet test test/KubeOps.Operator.Test/KubeOps.Operator.Test.csproj
dotnet test --project test/KubeOps.Operator.Test/KubeOps.Operator.Test.csproj

# Run only unit tests (skip integration tests) — no cluster required
dotnet test test/KubeOps.Operator.Test/ --filter "FullyQualifiedName!~Integration"
dotnet test --project test/KubeOps.Operator.Test/KubeOps.Operator.Test.csproj \
--filter-not-trait "Category=Integration"

# Run a single test by name
dotnet test --filter "FullyQualifiedName~MyTestClass.MyTestMethod"
Expand All @@ -43,7 +44,8 @@ dotnet test --filter "FullyQualifiedName~MyTestClass.MyTestMethod"
- Integration tests inherit `IntegrationTestBase`, override
`ConfigureHost(HostApplicationBuilder)` to wire up the operator under test, and use
`TestNamespaceProvider` for namespace isolation. The shared integration collection disables
parallelization and installs the required CRDs once per run.
parallelization and installs the required CRDs once per run. `IntegrationTestBase` also applies
the `Category=Integration` trait so integration tests can be excluded consistently.

When you add a feature, cover it with unit tests; if it changes the watch → queue → reconcile
behavior against a real API server, add an integration test as well.
2 changes: 1 addition & 1 deletion docs/docs/operator/testing/integration-tests.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ jobs:
- name: Setup .NET
uses: actions/setup-dotnet@v3
with:
dotnet-version: 9.x
dotnet-version: 10.x

- name: Create Kubernetes Cluster
uses: helm/kind-action@v1.12.0
Expand Down
5 changes: 5 additions & 0 deletions global.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"test": {
"runner": "Microsoft.Testing.Platform"
}
}
14 changes: 7 additions & 7 deletions test/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,19 @@
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<IsPackable>false</IsPackable>
<IsTestProject>true</IsTestProject>
<IsTestProject>$(MSBuildProjectName.EndsWith('.Test'))</IsTestProject>
<EnablePreviewFeatures>true</EnablePreviewFeatures>
</PropertyGroup>

<ItemGroup>
<ItemGroup Condition="'$(IsTestProject)' == 'true'">
<PackageReference Include="FluentAssertions" Version="8.10.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="18.9.0" />
<PackageReference Include="xunit.v3" Version="3.2.2" />
<PackageReference Include="xunit.runner.visualstudio" Version="3.1.5">
<PackageReference Include="xunit.v3" Version="4.0.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="4.0.0">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="xunit.analyzers" Version="1.27.0">
<PackageReference Include="xunit.analyzers" Version="2.0.0">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
Expand All @@ -26,9 +26,9 @@
</PackageReference>
</ItemGroup>

<ItemGroup>
<ItemGroup Condition="'$(IsTestProject)' == 'true'">
<ProjectReference Include="$(MSBuildThisFileDirectory)\..\src\KubeOps.Abstractions\KubeOps.Abstractions.csproj" />
<Using Include="Xunit"/>
</ItemGroup>

</Project>
</Project>
3 changes: 2 additions & 1 deletion test/KubeOps.Cli.Test/Management/Install.Integration.Test.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@

namespace KubeOps.Cli.Test.Management;

public class InstallIntegrationTest
[Trait("Category", "Integration")]
public sealed class InstallIntegrationTest
{
private static readonly string ProjectPath =
Path.Join(Directory.GetCurrentDirectory(), "..", "..", "..", "..", "..", "examples", "Operator",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@ public class IntegrationTestCollection
}

[Collection(IntegrationTestCollection.Name)]
[Trait("Category", "Integration")]
public abstract class IntegrationTestBase;
1 change: 1 addition & 0 deletions test/KubeOps.Operator.Test/IntegrationTestCollection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ public class IntegrationTestCollection : ICollectionFixture<CrdInstaller>
}

[Collection(IntegrationTestCollection.Name)]
[Trait("Category", "Integration")]
public abstract class IntegrationTestBase : IAsyncLifetime
{
private IHost? _host;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ public class IntegrationTestCollection : ICollectionFixture<CrdInstaller>, IColl
}

[Collection(IntegrationTestCollection.Name)]
[Trait("Category", "Integration")]
public abstract class IntegrationTestBase;

public sealed class CrdInstaller : IAsyncLifetime
Expand Down
Loading