| name | testing |
|---|---|
| description | Use for MSTest projects, unit vs integration tests, coverlet/TRX output, and local credentials in contentstack-management-dotnet. |
- Adding or fixing unit or integration tests.
- Reproducing CI test failures (TRX, coverage).
- Setting up
appsettings.jsonfor integration tests.
| Project | Path | Purpose |
|---|---|---|
| Unit tests | Contentstack.Management.Core.Unit.Tests/ |
Fast, isolated tests; this is what CI runs via Scripts/run-unit-test-case.sh. |
| Integration tests | Contentstack.Management.Core.Tests/ |
Real API tests under IntegrationTest/; requires credentials. |
- Framework: MSTest (
Microsoft.VisualStudio.TestTools.UnitTesting). - Target framework:
net7.0for both test projects. - Coverage:
coverlet.collectorwith--collect:"XPlat code coverage"in the unit test script.
From repo root:
sh ./Scripts/run-unit-test-case.sh- TRX output:
Contentstack.Management.Core.Unit.Tests/TestResults/Report-Contentstack-DotNet-Test-Case.trx(logger file name in script). - The script deletes
Contentstack.Management.Core.Unit.Tests/TestResultsbefore running.
- Helper:
Contentstack.Management.Core.Tests/Contentstack.csloadsappsettings.jsonviaConfigurationBuilderand exposesContentstack.CreateAuthenticatedClient()(login using credentials from config—never commit real secrets). - Add
appsettings.jsonlocally (it is not checked in; keep secrets out of git). Structure includesContentstacksection and nestedContentstack:Credentials,Contentstack:Organizationas used by the tests. - Integration tests use
[ClassInitialize]/[DoNotParallelize]in many classes; follow existing patterns when adding scenarios.
- Do not commit TRX zips, ad-hoc
TestResultsarchives, or credential files. - Prefer deterministic unit tests with mocks (see existing
Mokes//Mock/usage in unit tests).
This repo uses MSTest (Microsoft.VisualStudio.TestTools.UnitTesting), not xUnit. Many tests also use AutoFixture, AutoFixture.AutoMoq, and Moq.
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace Contentstack.Management.Core.Unit.Tests.YourArea
{
[TestClass]
public class YourFeatureTest
{
[TestInitialize]
public void Setup()
{
// Per-test setup
}
[TestMethod]
public void YourScenario_DoesExpectedThing()
{
Assert.IsNotNull(result);
}
}
}Common in HTTP and service tests (ContentstackHttpRequestTest.cs):
using AutoFixture;
using AutoFixture.AutoMoq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
[TestClass]
public class YourFeatureTest
{
private readonly IFixture _fixture = new Fixture()
.Customize(new AutoMoqCustomization());
[TestMethod]
public void Example()
{
var value = _fixture.Create<string>();
Assert.IsFalse(string.IsNullOrEmpty(value));
}
}Pipeline tests often build ExecutionContext, RequestContext, ResponseContext, attach a RetryPolicy, and use test doubles from Mokes/ (e.g. MockHttpHandlerWithRetries, MockService). See RetryHandlerTest.cs.
Integration tests live in Contentstack.Management.Core.Tests, use [ClassInitialize], [DoNotParallelize] in many classes, and Contentstack.CreateAuthenticatedClient() from Contentstack.cs. Do not use this pattern in the unit test project for network I/O.
- CI parity (unit):
sh ./Scripts/run-unit-test-case.shfrom repo root. - Single project:
dotnet test Contentstack.Management.Core.Unit.Tests/Contentstack.Management.Core.Unit.Tests.csproj
Exact dotnet test arguments are in Scripts/run-unit-test-case.sh.