Quick wins for a faster PC:
Fix the driver behind crashes, sound loss and screen glitchesFind Drivers →Clear out junk files and repair common Windows errorsFree Scan →Scan for outdated or missing drivers - takes under a minuteDriver Scan →For a new xUnit.net project, install the xUnit.net v3 templates, create a test project with dotnet new xunit3, then run it with dotnet run. If you already have an xUnit.net v2 project, keep to its matching setup: the documented v2 route uses dotnet new xunit and dotnet test. The commands differ because the project templates and test runners differ; do not mix them.
Run a new xUnit.net v3 test project
The .NET SDK supplies the dotnet command-line interface (CLI) used below. The steps follow xUnit.net’s v3 getting-started guide. Its examples are documentation examples, not a promise that your output or generated files will be identical: templates and defaults can vary with SDK and template releases.
- Install and check the .NET SDK. Install the SDK for your operating system, open a new terminal, and run
dotnet --version. The guide’s sample prints10.0.102; that is an example SDK version, not a required version. If the command is not found, install the SDK or fix your PATH, then open a fresh terminal. - Install the xUnit.net v3 templates. Run
dotnet new install xunit.v3.templates. The package includesxunit3andxunit3-extensiontemplates, with C#, F#, and VB.NET support. Usexunit3for an ordinary test project. - Create a project. Run these commands in the terminal:
mkdir MyFirstUnitTests cd MyFirstUnitTests dotnet new xunit3The template restores the generated project as part of creation in the guide’s example. If you create your test project inside a solution or an existing repository instead, make sure you run later commands from the directory containing the test project’s
.csproj. - Inspect the generated test. In the C# template, open
UnitTest1.cs. The documented example contains a class with a[Fact]test andAssert.True(true). That assertion is a placeholder: it proves the runner can discover and execute a test, but checks no application behavior. - Run the test project. From the test-project directory, run:
dotnet runA successful run should report test discovery and execution, with no errors or failures. The guide’s example reports one test; treat that as sample output, not as a fixed count or byte-for-byte output for every SDK and template.
Replace the placeholder with a useful assertion
A test is valuable when its assertion checks behavior that matters. For example, suppose the project has an Add method. A test can assert that adding 2 and 2 returns 4:
using Xunit;
public class UnitTest1
{
[Fact]
public void Add_TwoNumbers_ReturnsTheirSum()
{
Assert.Equal(4, Add(2, 2));
}
private static int Add(int left, int right) => left + right;
}
This compact example keeps the method in the test class so it can stand alone. In an actual application, test the method in the production project rather than defining a second copy inside the test. A deliberately incorrect expected value, such as Assert.Equal(5, Add(2, 2)), should fail; the runner’s diagnostic identifies expected and actual values and a source location. A failure here is useful evidence that the test can detect an incorrect result.
Do these 3 things before closing this tab:
1Clear out junk files and repair common Windows errors2Scan for outdated or missing drivers - takes under a minute3Repair Windows errors before they cause bigger problemsUse a fact for an invariant
A [Fact] test checks a condition expected to hold for the particular case it exercises. xUnit.net’s v3 guide puts it this way: “Facts are tests which are always true. They test invariant conditions.”
Use a theory for several inputs
A [Theory] runs the same test logic against supplied data, commonly with [InlineData]. For example:
using Xunit;
public class AdditionTests
{
[Theory]
[InlineData(2, 2, 4)]
[InlineData(-1, 1, 0)]
[InlineData(0, 5, 5)]
public void Add_ReturnsExpectedSum(int left, int right, int expected)
{
Assert.Equal(expected, Add(left, right));
}
private static int Add(int left, int right) => left + right;
}
The runner executes this theory once per supplied row. If one row fails, its input helps identify the case to investigate.
Choose the command that matches your xUnit version and runner
Do not choose a command solely because it is familiar: use the setup configured for the project. The v3 getting-started guide’s default project is configured for Microsoft Testing Platform and runs with dotnet run. The separate xUnit.net v2 guide demonstrates a VSTest setup and runs with dotnet test.
| Setup | Template command | Documented runner path | Execution command |
|---|---|---|---|
| xUnit.net v3, new project | dotnet new xunit3 |
The getting-started default uses Microsoft Testing Platform. The guide says selecting VSTest adds xunit.runner.visualstudio and Microsoft.NET.Test.Sdk. |
dotnet run for the default documented setup; follow the matching runner instructions if you choose VSTest. |
| xUnit.net v2, existing or intentionally created project | dotnet new xunit |
The v2 guide’s VSTest route references xunit, xunit.runner.visualstudio, and Microsoft.NET.Test.Sdk. |
dotnet test for the documented VSTest setup. |
The v2 guide, dated July 4, 2025, describes xUnit.net v2 as being in maintenance mode: critical bug fixes continue, while new feature work is in v3. That is not a reason to replace packages in an existing project blindly. Check its project file and follow the instructions for the configured version and runner. For template and runner details, see the xUnit.net What’s New page as well as the applicable getting-started guide.
Run tests from an editor if you prefer
A terminal is enough to create and run the first test. If you prefer an IDE, the xUnit.net documentation also describes Visual Studio Test Explorer and VS Code with Microsoft’s C# Dev Kit. Discovery depends on the test project and runner package configuration; for example, the documented VSTest path uses its runner-related package references. An editor is optional, not a prerequisite for the command-line route.
Rank #4
Troubleshoot common first-run problems
dotnetis not recognized or not found: the SDK may not be installed, or the terminal may not see its installation directory on PATH. Install the SDK for your operating system, check the installation, and open a fresh terminal before retryingdotnet --version.- The template name is unavailable: for the v3 template, install
xunit.v3.templateswithdotnet new install xunit.v3.templates, then retrydotnet new xunit3. The documented v2 template name isxunit, notxunit3. - No tests are discovered, or the command behaves unexpectedly: confirm that you are in the test project directory and that you are using the command for its version and runner setup. The v3 default shown in the guide uses Microsoft Testing Platform and
dotnet run; the documented v2 VSTest route usesdotnet testand its package references. - A test fails: read the expected and actual values and the reported source location. If you intentionally changed the expected result to test failure reporting, restore the correct assertion; otherwise, inspect the code and the inputs for the failing case.
- Editor discovery differs from the terminal: check that the editor’s test integration matches the project runner and that the required runner packages are present for the chosen configuration. Use the version-specific xUnit.net instructions rather than adding v2 and v3 setup pieces interchangeably.
Or skip the browser setup
xUnit tests run in a .NET project, so ScreenshotNeo is not needed to create or execute this test. If your developer workflow also needs website screenshots, ScreenshotNeo offers a one-request API. For example, save a screenshot of https://stripe.com as shot.webp with cURL:
curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.webp
See the ScreenshotNeo API documentation for request options. It accepts consent banners like a visitor and removes more than 60 known consent platforms, newsletter popups, and chat widgets before capture; each step can be turned off. Bot checks, blank pages, timeouts, failed loads, and cache hits cost nothing, and response headers indicate the page verdict and billing status. ScreenshotNeo also has an MCP server with screenshot and PDF tools for AI agents. The free plan includes 1,000 screenshots per month with no card; paid plans start at $5 for 3,000 screenshots.
Recommended Free Tools
Learn about ScreenshotNeo, or sign up free for 1,000 screenshots a month with no card.
Quick Recap
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.




