---
title: Set up .NET, Selenium and NUnit | TestingBot
description: This chapter creates the test project, adds Selenium, and runs a first
  test against a real browser. It takes about ten minutes, most of it waiting for…
source_url:
  html: https://testingbot.com/resources/courses/selenium-csharp/setup-and-first-test
  md: https://testingbot.com/resources/courses/selenium-csharp/setup-and-first-test.md
---

Course

[Selenium C# Tutorial with NUnit](https://testingbot.com/resources/courses/selenium-csharp)

Chapter 2 of 10

1. [1 Selenium C# Tutorial with NUnit](https://testingbot.com/resources/courses/selenium-csharp)
2. [2 Set up .NET, Selenium and NUnit](https://testingbot.com/resources/courses/selenium-csharp/setup-and-first-test)
3. [3 Selenium C# locators and WebDriverWait](https://testingbot.com/resources/courses/selenium-csharp/locators-and-waits)
4. [4 NUnit fixtures, attributes and [TestCase] ](https://testingbot.com/resources/courses/selenium-csharp/nunit-fixtures-and-attributes)
5. [5 NUnit assertions and screenshots on failure](https://testingbot.com/resources/courses/selenium-csharp/assertions-and-screenshots)
6. [6 Page objects in C#](https://testingbot.com/resources/courses/selenium-csharp/page-objects)
7. [7 Run Selenium C# tests on the TestingBot grid](https://testingbot.com/resources/courses/selenium-csharp/run-on-testingbot)
8. [8 Parallel Selenium tests with NUnit](https://testingbot.com/resources/courses/selenium-csharp/parallel-tests)
9. [9 Selenium C# tests in CI](https://testingbot.com/resources/courses/selenium-csharp/ci-with-github-actions)
10. [10 Selenium C# Quiz](https://testingbot.com/resources/courses/selenium-csharp/knowledge-check)

[Exit course](https://testingbot.com/resources/courses)

 Chapter 2 of 10 Intermediate 6 min read 2 quick checks Updated Nov 2026 

# Set up .NET, Selenium and NUnit
On this page
1. [Install the .NET SDK](https://testingbot.com#install-the-net-sdk)
2. [Create an NUnit project](https://testingbot.com#create-an-nunit-project)
3. [The first test](https://testingbot.com#the-first-test)
4. [The analyzer's first complaint](https://testingbot.com#the-analyzer-s-first-complaint)
5. [Run it](https://testingbot.com#run-it)
6. [Running a subset](https://testingbot.com#running-a-subset)

This chapter creates the test project, adds Selenium, and runs a first test against a real browser. It takes about ten minutes, most of it waiting for downloads.

## Install the .NET SDK[#](https://testingbot.com#install-the-net-sdk)

Check what you have:

```bash
dotnet --list-sdks
```

If the list is empty or the command is missing, install the SDK from [dot.net](https://dotnet.microsoft.com/download), or with a package manager:

```bash
# Windows
winget install Microsoft.DotNet.SDK.10

# macOS
brew install --cask dotnet-sdk
```

On Linux, Microsoft's [install page](https://learn.microsoft.com/dotnet/core/install/linux) lists the package source for each distribution.

The examples were run with SDK 10.0.404. Any 10.0 SDK works; so does a .NET 8 SDK if you change `net10.0` to `net8.0` in the project file below. You do not need Visual Studio. Every command here runs from a terminal, and VS Code, Rider and Visual Studio all open the same project.

## Create an NUnit project[#](https://testingbot.com#create-an-nunit-project)

The SDK ships a project template for NUnit:

```bash
dotnet new nunit -n SeleniumCourse
cd SeleniumCourse
dotnet add package Selenium.WebDriver
dotnet add package Selenium.Support
```

`Selenium.WebDriver` is the WebDriver client, including `WebDriverWait`. `Selenium.Support` adds helpers such as `SelectElement` for dropdowns. Do **not** add `Selenium.WebDriver.ChromeDriver` or similar driver packages: they pin a driver binary that falls out of date the next time Chrome updates itself.

The template's package versions lag behind. On SDK 10.0.404 it generated NUnit 4.3.2 and NUnit3TestAdapter 5.0.0, while NUnit 5.0.0 and adapter 6.3.1 were current. `dotnet add package` without a version installs the latest, so run it again for the test packages:

```bash
dotnet add package NUnit
dotnet add package NUnit3TestAdapter
dotnet add package Microsoft.NET.Test.Sdk
dotnet add package NUnit.Analyzers
```

Delete the generated `UnitTest1.cs`. The project file now looks like this (we also removed `coverlet.collector`, which measures code coverage and is no use for browser tests):

```xml
<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <TargetFramework>net10.0</TargetFramework>
    <ImplicitUsings>enable</ImplicitUsings>
    <Nullable>enable</Nullable>
    <IsPackable>false</IsPackable>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="Microsoft.NET.Test.Sdk" Version="18.12.0" />
    <PackageReference Include="NUnit" Version="5.0.0" />
    <PackageReference Include="NUnit3TestAdapter" Version="6.3.1" />
    <PackageReference Include="NUnit.Analyzers" Version="4.15.0">
      <PrivateAssets>all</PrivateAssets>
    </PackageReference>
    <PackageReference Include="Selenium.Support" Version="4.52.0" />
    <PackageReference Include="Selenium.WebDriver" Version="4.52.0" />
  </ItemGroup>

  <ItemGroup>
    <Using Include="NUnit.Framework" />
  </ItemGroup>

</Project>
```

Three packages make `dotnet test` work, and leaving one out is the most common reason for "No test is available":

| Package | Job |
| --- | --- |
| `NUnit` | the attributes and `Assert` you write tests with |
| `NUnit3TestAdapter` | lets `dotnet test` and IDEs discover and run NUnit tests (the name is historical; it runs NUnit 3, 4 and 5) |
| `Microsoft.NET.Test.Sdk` | the test host that `dotnet test` starts |

`NUnit.Analyzers` is optional but worth keeping: it turns common NUnit mistakes into compiler warnings and errors, as you are about to see. The `<Using Include="NUnit.Framework" />` line is a global using, so test files do not need their own `using NUnit.Framework;`.

A colleague's project has `NUnit` and `Selenium.WebDriver`, builds fine, but `dotnet test` runs nothing. What is the likely cause?

 The test methods are not `static`. ChromeDriver is not on the PATH. `NUnit3TestAdapter` or `Microsoft.NET.Test.Sdk` is missing, so nothing discovers the tests.

The NUnit package only provides the attributes. Discovery needs the adapter and the test SDK. A missing driver would make tests fail, not disappear, and NUnit test methods are instance methods.

## The first test[#](https://testingbot.com#the-first-test)

Create `FirstTest.cs`:

```csharp
using OpenQA.Selenium;
using OpenQA.Selenium.Chrome;

namespace SeleniumCourse;

public class FirstTest
{
    private IWebDriver driver = null!;

    [SetUp]
    public void StartBrowser()
    {
        driver = new ChromeDriver();
    }

    [Test]
    public void WebFormHasTheRightTitle()
    {
        driver.Navigate().GoToUrl("https://www.selenium.dev/selenium/web/web-form.html");

        Assert.That(driver.Title, Is.EqualTo("Web form"));
    }

    [TearDown]
    public void StopBrowser()
    {
        driver.Quit();
    }
}
```

NUnit creates the class, calls the `[SetUp]` method, then the `[Test]` method, then the `[TearDown]` method, which runs whether the test passed or failed. `= null!` tells the compiler's nullable checks that the field is set before use (in `SetUp`), which it cannot see by itself.

## The analyzer's first complaint[#](https://testingbot.com#the-analyzer-s-first-complaint)

Run `dotnet test` and the build fails before any browser starts:

```
FirstTest.cs(8,24): error NUnit1032: The field driver should be Disposed in a method annotated with [TearDownAttribute]
```

`IWebDriver` is `IDisposable`, and the analyzer wants every disposable field disposed in a teardown. It does not know that Selenium's `Quit()` does exactly that: the API documentation describes it as "Close the Browser and Dispose of WebDriver". Tell the analyzer once, in an `.editorconfig` file next to the project file:

```ini
root = true

[*.cs]
# Selenium's Quit() closes the browser and disposes the driver
dotnet_diagnostic.NUnit1032.additional_dispose_methods = Quit
```

The alternative, calling `driver.Dispose()` instead of `Quit()`, also satisfies it, but `Quit()` is what every Selenium example uses and what readers of your code will look for.

## Run it[#](https://testingbot.com#run-it)

```bash
dotnet test
```

```
Passed! - Failed: 0, Passed: 1, Skipped: 0, Total: 1, Duration: 1 s - SeleniumCourse.dll (net10.0)
```

A Chrome window opens, loads the form and closes again. The first run takes longer because Selenium Manager looks up your Chrome version and, if needed, downloads a matching ChromeDriver into a cache folder (`~/.cache/selenium` on macOS and Linux, `%USERPROFILE%\.cache\selenium` on Windows). Later runs reuse it. If Chrome is not installed at all, Selenium Manager can download a Chrome for Testing build as well.

To see each test's name and outcome rather than just the summary, raise the console logger's verbosity:

```bash
dotnet test --logger "console;verbosity=normal"
```

```
Passed WebFormHasTheRightTitle [1 s]
```

Chrome updated overnight and a project that references the `Selenium.WebDriver.ChromeDriver` package now fails with "This version of ChromeDriver only supports Chrome version ...". What is the lasting fix?

 Pin Chrome to an older version on every machine. Remove the driver package and let Selenium Manager, built into `Selenium.WebDriver`, resolve the matching driver. Update the driver package every time Chrome updates.

Selenium Manager matches the driver to the installed browser at run time, so browser updates stop breaking the suite. Bumping the package works until the next Chrome release, and pinning the browser means testing against a version your users no longer run.

## Running a subset[#](https://testingbot.com#running-a-subset)

As the suite grows you will want to run part of it. `dotnet test --filter` selects by name, class or category:

```bash
dotnet test --filter "Name=WebFormHasTheRightTitle"
dotnet test --filter "FullyQualifiedName~FirstTest" # ~ means "contains"
dotnet test --list-tests # show what would run
```

Chapter 3 adds categories, which are the better long-term way to group tests. The next chapter is about the part of Selenium where most of the real work happens: finding elements and waiting for them.

[Previous · Chapter 1 Selenium C# Tutorial with NUnit](https://testingbot.com/resources/courses/selenium-csharp) [Next · Chapter 3 Selenium C# locators and WebDriverWait](https://testingbot.com/resources/courses/selenium-csharp/locators-and-waits)

On this page

1. [Install the .NET SDK](https://testingbot.com#install-the-net-sdk)
2. [Create an NUnit project](https://testingbot.com#create-an-nunit-project)
3. [The first test](https://testingbot.com#the-first-test)
4. [The analyzer's first complaint](https://testingbot.com#the-analyzer-s-first-complaint)
5. [Run it](https://testingbot.com#run-it)
6. [Running a subset](https://testingbot.com#running-a-subset)

Certification

Earn the free, resume-worthy TestingBot Selenium C# Certification for this course.

[How it works](https://testingbot.com/resources/courses/selenium-csharp/certification)
