Test framework and runner boundaries
Test framework and runner boundaries
A test framework defines attributes, assertions and lifecycle rules. A test platform discovers and executes tests and reports results. With the .NET 10 SDK, dotnet test defaults to VSTest unless the Microsoft.Testing.Platform runner is selected in global.json. That dedicated mode requires MTP-compatible test applications and its own command-line options. Confirm actual discovery counts and failure exit codes; a successful build or zero discovered tests is not evidence of the intended behavior. Coverage tools record which code was reached. These layers are related but not interchangeable. This lesson compares the same nonnegative fee rule in xUnit.net v3, NUnit 4.x and modern MSTest; exact compatible package and adapter versions must be selected and verified before running the fixtures.
Proposed baseline: .NET SDK 10.0.404, net10.0 / C# 14. All results are reasoned, not executed. Build and test examples require an approved isolated environment. Framework examples are separate test classes, not console entry points.
xUnit: Fact and Assert.Equal
Place this class in a reviewed xUnit.net v3 test project. The class uses the xUnit namespace and no other framework.
using Xunit;public class FeeTests{ [Fact] public void AtThreshold_IsFree() { Assert.Equal(0, Fee(50)); } private static int Fee(int total) => total < 50 ? 5 : 0;}The first assertion argument is expected, the second is actual. xUnit v3 supports multiple runner integrations; choose one documented for the selected package set.
Expected observation (reasoned, not executed):
One expected passing test if the configured runner discovers and executes it.NUnit: TestCase and constraint assertion
Place in a separate reviewed NUnit 4.x test project with the required runner integration. Use NUnit constraint syntax, not xUnit assertions.
using NUnit.Framework;public class FeeTests{ [TestCase(49, 5)] [TestCase(50, 0)] public void Fee_MatchesRule(int total, int expected) { Assert.That(Fee(total), Is.EqualTo(expected)); } private static int Fee(int total) => total < 50 ? 5 : 0;}Assert.That takes the actual value and a constraint describing the expected result. NUnit lifecycle and runner settings differ from xUnit.
Expected observation (reasoned, not executed):
Two expected passing cases if discovered and executed.MSTest: TestClass, TestMethod and DataRow
Place in a separate reviewed MSTest project. This fixture uses the Microsoft.VisualStudio.TestTools.UnitTesting namespace.
using Microsoft.VisualStudio.TestTools.UnitTesting;[TestClass]public class FeeTests{ [TestMethod] [DataRow(49, 5)] [DataRow(50, 0)] public void Fee_MatchesRule(int total, int expected) { Assert.AreEqual(expected, Fee(total)); } private static int Fee(int total) => total < 50 ? 5 : 0;}DataRow provides input and expected output; TestClass and TestMethod establish the MSTest test structure. These are framework fixtures, not console entry points.
Expected observation (reasoned, not executed):
Two expected passing cases if discovered and executed.Common mistakes and edge cases
The .NET 10 SDK supports VSTest and Microsoft.Testing.Platform (MTP) modes for dotnet test. MTP mode is selected in global.json with a test.runner value of Microsoft.Testing.Platform; use only compatible MTP test projects and the documented CLI options for that mode. VSTest adapters and MTP extensions are not interchangeable. Do not copy flags between modes without checking documentation. Pin SDK, framework and runner packages; restore from approved sources before testing. No test discovery, package restore, framework execution or coverage has been performed here. Zero discovered tests is not a successful behavior check. Even 100% line coverage would not prove correct assertions or boundary behavior.
Practice and recap
A CI log shows a successful build but zero tests discovered. List the checks needed before accepting the result.
Hint: Separate project discovery, framework metadata and runner integration.
Learning objective: Separate assertion libraries, runner and coverage. See accompanying manual practice and knowledge check.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Test framework and runner boundaries — knowledge check
Apply the lesson concepts to the following scenarios.
Which component discovers and executes test methods?
Which assertion belongs to NUnit constraint syntax?
Which attributes belong to the MSTest data-driven example?
What should CI do when zero tests are discovered unexpectedly?
What does line coverage measure?