Unit Testing 101: Write your first unit test in C# with MSTest (2022)

Do you want to start writing unit tests and you don't know how to start? Were you asked to write some unit tests on a past interview? Let's see what is a unit test and how to write your first unit tests in C#.

What is a unit test?

The book The Art of Unit Testing defines a unit test as "an automated piece of code that invokes a unit of work in the system and then checks a single assumption about the behavior of that unit of work."

From the previous definition, a unit of work is any logic exposed through public methods. Often, a unit of work returns a value, changes the internals of the system, or makes an external invocation.

If that definition answers how to test public methods, we might ask: 'What about private methods?' Short answer: we don't test them. We test private methods when we call our code through its public methods.

In short, a unit test is code that invokes some code under test and verifies a given behavior of that code.

Why should we write unit tests?

Have you ever needed to change your code, but you were concerned about breaking something? I've been there too.

The main reason to write unit tests is to gain confidence. Unit tests allow us to make changes, with confidence that they will work. Unit tests allow change.

Unit tests work like a "safety net" to prevent us from breaking things when we add features or change our codebase.

In addition, unit tests work like a living documentation. The first end-user of our code is our unit tests. If we want to know what a library does, we should check its unit tests. Often, we will find not-documented features in the tests.

Unit Testing 101: Write your first unit test in C# with MSTest (1)

What makes a good unit test?

Now, we know what is a unit test and why we should write them. The next question we need to answer is: 'What makes a test a good unit test?' Let's see what all good unit tests have in common.

Our tests should run quickly. The longer our tests take to run, the less frequent we run them. And, if we don't run our tests often, we have doors opened to bugs.

Our tests should run in any order. Tests shouldn't depend on the output of previous tests to run. A test should create its own state and not rely upon the state of other tests.

(Video) C# Unit Testing using MSTest Test Projects in Visual Studio

Our tests should be deterministic. No matter how many times we run our tests, they should either fail or pass every time. We don't want our test to use random input, for example.

Our tests should validate themselves. We shouldn't debug our tests to make sure they passed or failed. Each test should determine the success or failure of the tested behavior. Imagine we have hundreds of tests and to make sure they pass, we have to debug every one of them. What's the point, then?

"It could be considered unprofessional to write code without tests" - Robert Martin, The Clean Coder

Let's write our first unit test

Let's write some unit tests for Stringie, a (fictional) library to manipulate strings with more readable methods.

One of Stringie methods is Remove(). It removes chunks of text from an string. For example, Remove() receives a substring to remove. Otherwise it returns an empty string if we don't pass any parameters.

"Hello, world!".Remove("Hello");// ", world!""Hello, world!".Remove();// ""

Here's the implementation of the Remove() method for the scenario without parameters.

namespace Stringie{ public static class RemoveExtensions { public static RemoveString Remove(this string source) { return new RemoveString(source); } } public class RemoveString { private readonly string _source; internal RemoveString(string source) { _source = source; } public static implicit operator string(RemoveString removeString) { return removeString.ToString(); } public override string ToString() { return _source != null ? string.Empty : null; } }}

Let's write some tests for the Remove() method. We can write a Console program to test these two scenarios.

using Stringie;using System;namespace TestProject{ class Program { static void Main(string[] args) { var helloRemoved = "Hello, world!".Remove("Hello"); if (helloRemoved == ", world!") { Console.WriteLine("Remove Hello OK"); } else { Console.WriteLine($"Remove Hello failed. Expected: ', world!'. But it was: '{helloRemoved}'"); } var empty = "Hello, world!".Remove(); if (string.IsNullOrEmpty(empty)) { Console.WriteLine("Remove: OK"); } else { Console.WriteLine($"Remove failed. Expected: ''. But it was: {empty}"); } Console.ReadKey(); } }}

However, these aren't real unit tests. They run quickly, but they don't run in any order and they don't validate themselves.

Where should we put our tests?

Let's create a new project. Let's add to the solution containing Stringie a new project of type "MSTest Test Project (.NET Core)". Since we're adding tests for the Stringie project, let's name our new test project Stringie.UnitTests.

It's my recommendation to put our unit tests in a test project named after the project they test. We can add the suffix "Tests" or "UnitTests". For example, if we have a library called MyLibrary, we should name our test project: MyLibrary.UnitTests.

In our new test project, let's add a reference to the Stringie project.

Unit Testing 101: Write your first unit test in C# with MSTest (2)

After adding the new test project, Visual Studio created a file UnitTest1.cs. Let's rename it! We are adding tests for the Remove() method, let's name this file: RemoveTests.cs.

One way of making our tests easy to find and group is to put our unit tests separated in files named after the unit of work or entry point of the code we're testing. Let's add the suffix "Tests". For a class MyClass, let's name our file: MyClassTests.

(Video) Unit Testing C# with MSTest in Visual Studio 2022 - Part 1 | Unit Testing C# Tutorial


Now, let's see what's inside our RemoveTests.cs file.

using Microsoft.VisualStudio.TestTools.UnitTesting;namespace Stringie.UnitTests{ [TestClass] public class RemoveTests { [TestMethod] public void TestMethod1() { } }}

It contains one normal class and method. However, they're annotated with two unusual attributes: [TestClass] and [TestMethod]. These attributes tell Visual Studio that our file contains unit tests to run.

The [TestClass] and [TestMethod] attributes belong to a project called MSTest. Microsoft Test Framework (MSTest) is an open source unit testing framework. MSTest comes installed with Visual Studio.

Unit testing frameworks help us to write and run unit tests. Also, they create reports with the results of our tests. Other common unit testing frameworks include NUnit and XUnit.

How should we name our tests?

Let's replace the name TestMethod1 with a name that follows a naming convention.

We should use naming conventions to show the feature tested and the purpose behind of our tests. Tests names should tell what they're testing. A name like TestMethod1 doesn't say anything about the code under test and the expected result.

One naming convention for our test names uses a sentence to tell what they're testing. Often these names start with the prefix "ItShould" follow by an action. For our Remove() method, it could be: "ItShouldRemoveASubstring" and "ItShouldReturnEmpty".

Unit Testing 101: Write your first unit test in C# with MSTest (3)

Another convention uses underscores to separate the unit of work, the test scenario and the expected behavior in our test names. If we follow this convention for our example tests, we name our tests: Remove_ASubstring_RemovesThatSubstring() and Remove_NoParameters_ReturnsEmpty().

With this convention, we can read our test names out loud like this: "When calling Remove with a substring, then it removes that substring".

These names could look funny at first glance. We should use compact names in our code. However, when writing unit tests, readability is important. Every test should state the scenario under test and the expected result. We shouldn't worry about long test names.

Following the second naming convention, our tests look like this:

using Microsoft.VisualStudio.TestTools.UnitTesting;namespace Stringie.UnitTests{ [TestClass] public class RemoveTests { [TestMethod] public void Remove_ASubstring_RemovesThatSubstring() { } [TestMethod] public void Remove_NoParameters_ReturnsEmpty() { } }}

How should we write our tests?

Now, let's write the body of our tests.

(Video) Writing tests with MSTest v2

To write our tests, let's follow the Arrange/Act/Assert (AAA) principle. Each test should contain these three parts.

In the Arrange part, we create input values to call the entry point of the code under test.

In the Act part, we call the entry point to trigger the logic being tested.

In the Assert part, we verify the expected behavior of the code under test.

Let's use the AAA principle to replace one of our examples with a real test. Also, let's use line breaks to visually separate the AAA parts.

using Microsoft.VisualStudio.TestTools.UnitTesting;namespace Stringie.UnitTests{ [TestClass] public class RemoveTests { [TestMethod] public void Remove_NoParameters_ReturnsEmpty() { string str = "Hello, world!"; string transformed = str.Remove(); Assert.AreEqual(0, transformed.Length); } }}

We used the Assert class from MSTest to write the Assert part of our test. This class contains methods like AreEqual(), IsTrue() and IsNull().

The AreEqual() method checks if the result from a test is equal to an expected value. In our test, we used it to verified the length of the transformed string. We expect it to be zero.

Let's use a known value in the Assert part instead of repeating the logic under test in the assertions. It's OK to hardcode some expected values in our tests. We shouldn't repeat the logic under test in our assertions. For example, we can use well-named constants for our expected values.

Here's an example of how not to write the Assertion part of our second test.

[TestMethod]public void Remove_ASubstring_RemovesThatSubstring(){ string str = "Hello, world!"; string transformed = str.Remove("Hello"); var position = str.IndexOf("Hello"); var expected = str.Substring(position + 5); Assert.AreEqual(expected, transformed);}

Notice how it uses the Substring() method in the Assert part to find the string without the Hello substring. A better alternative is to use the expected result in the AreEqual() method.

Let's rewrite our last test to use an expected value instead of repeating the logic being tested.

[TestMethod]public void Remove_ASubstring_RemovesThatSubstring(){ string str = "Hello, world!"; string transformed = str.Remove("Hello"); // Here we use the expected result ", world!" Assert.AreEqual(", world!", transformed)}

How can we run a test inside Visual Studio?

To run a test, let's right click on the [TestMethod] attribute of the test and use "Run Test(s)". Visual Studio will compile your solution and run the test you clicked on.

(Video) Unit Testing C# with MSTest in Visual Studio 2022 - Part 2 | Unit Testing C# Tutorial

After the test runs, let's go to the "Test Explorer" menu. There we will find the list of tests. A passed test has a green icon. If we don't have the "Test Explorer", we can use the "View" menu in Visual Studio and click "Test Explorer" to display it.

Unit Testing 101: Write your first unit test in C# with MSTest (4)

That's a passing test! Hurray!

If the result of a test isn't what was expected, the Assertion methods will throw an AssertFailedException. This exception or any other unexpected exception flags a test as failed.


These are some of the most common Assertion methods in MSTest.

Assert.AreEqualCheck if the expected value is equal to the found value
Assert.AreNotEqualCheck if the expected value isn't equal to the found value
Assert.IsTrueCheck if the found value is true
Assert.IsFalseCheck if the found value is false
Assert.IsNullCheck if the found value is null
Assert.IsNotNullCheck if the found value isn't null
Assert.ThrowsExceptionCheck if a method throws an exception
Assert.ThrowsExceptionAsyncCheck if an async method throws an exception
StringAssert.ContainsCheck if a found string contains a substring
StringAssert.MatchesCheck if a found string matches a regular expression
StringAssert.DoesNotMatchCheck if a found string doesn't matches a regular expression
CollectionAssert.AreEquivalentCheck if two collections contain the same elements
CollectionAssert.AreNotEquivalentCheck if two collections don't contain the same elements
CollectionAssert.ContainsCheck if a collection contains an element
CollectionAssert.DoesNotContainCheck if a collection doesn't contain an element


Voilà! That's how you write your first unit tests in C# with MSTest. Don't forget to follow naming conventions and use the Assert class when writing unit tests.

If you want to practice writing more test for Stringie, check my Unit Testing 101 repository over on GitHub.


Unit Testing Workshop for Beginners. Contribute to canro91/Testing101 development by creating an account on GitHub.

Unit Testing 101: Write your first unit test in C# with MSTest (5)GitHubcanro91

Unit Testing 101: Write your first unit test in C# with MSTest (6)

In this repository, you will find two lessons. One lesson to write some unit tests and another lesson to fix some unit tests.

(Video) 1. MsTest Framework || Part - 1.

Happy testing!


How do I set up MSTest? ›

MSTest Setup Visual Studio For Development and Testing
  1. Download The Latest Visual Studio.
  2. Install Necessary Platform For Development & Testing.
  3. Sign-In To Visual Studio IDE.
  4. Using Visual Studio IDE To Install The MSTest Framework.
  5. Using Package Manager Commands To Install The MSTest framework.
20 May 2020

What is the prerequisite to unit testing C# with MSTest and net? ›

Create the test project

The test project requires other packages to create and run unit tests. dotnet new in the previous step added the MSTest SDK, the MSTest test framework, the MSTest runner, and coverlet for code coverage reporting. You can see the entire file in the samples repository on GitHub.

Should I use MSTest or xUnit? ›

XUnit vs. MSTest is concerned, the biggest difference between xUnit and the other two test frameworks (NUnit and MSTest) is that xUnit is much more extensible when compared to NUnit and MSTest. The [Fact] attribute is used instead of the [Test] attribute.

How do you write a basic unit test? ›

  1. Test Small Pieces of Code in Isolation. ...
  2. Follow Arrange, Act, Assert. ...
  3. Keep Tests Short. ...
  4. Make Them Simple. ...
  5. Cover Happy Path First. ...
  6. Test Edge Cases. ...
  7. Write Tests Before Fixing Bugs. ...
  8. Make Them Performant.
28 May 2021

How do I run Mstest in Visual Studio? ›

To run all the tests in a default group, choose the Run icon and then choose the group on the menu. Select the individual tests that you want to run, open the right-click menu for a selected test and then choose Run Selected Tests (or press Ctrl + R, T).

How do you add MSTest to a project? ›

To enable VSTest adapters support, select the corresponding checkbox on the Build, Execution, Deployment | Unit Testing | VSTest page of JetBrains Rider settings Ctrl+Alt+S .

What is MSTest used for? ›

MSTest is one type of framework that provides the facility to test the code without using any third-party tool. It helps in writing effective unit tests using MSTest framework to test software applications. MSTest is a number-one open-source test framework that is shipped along with the Visual Studio IDE.

Is MSTest deprecated? ›

Test projects that are Coded UI tests or Web Load Tests are not compatible with MSTestV2. These project types have been deprecated.

Which is better NUnit or MSTest? ›

The main difference is the ability of MsTest to execute in parallel at the method level. Also, the tight integration of MsTest with Visual Studio provides advantages in both speed and robustness when compared to NUnit. As a result, I recommend MsTest.

How do I run MSTest without Visual Studio? ›

MSTest can be used without installing Visual Studio.
  1. Unzip.
  2. In the unzipped folder, copy the \tools\net451\Common7\IDE\Extensions\TestPlatform folder to the machine that has no Visual Studio installed.
  3. From cmd.exe run VSTest. console.exe MyTest. dll.
4 Nov 2008

How do I run MSTest from command line? ›

MSTest utility. To access the MSTest tool, add the Visual Studio install directory to the path or open the Visual Studio Group from the Start menu, and then open the Tools section to access the Visual Studio command prompt. Use the command MSTest from the command prompt.

Does Visual Studio use MSTest or VSTest? ›

The Visual Studio Tests build runner integrates functionality of the MSTest framework and VSTest console runner. Support for both frameworks enables TeamCity to execute tests and automatically import their test results.

Does MSTest work with .NET core? ›

There are three different test frameworks which are supported by the unit test with asp.net core: MSTest, xUnit, and NUnit, which allow us to test our code in a consistent way.

Does MSTest support .NET core? ›

Cross-Platform support – V2 version of the MSTest framework is a cross-platform implementation of the framework using which developers can write tests targeting . NET Framework, . NET Core, and ASP.NET Core on platforms like Linux, Mac, and Windows.

What is first unit test? ›

Unit Tests isolate a section of code and verify its correctness. A unit may be an individual function, method, procedure, module, or object. In SDLC, STLC, V Model, Unit testing is first level of testing done before integration testing.

What is a unit test example? ›

A Real-world Example

The above unit test “asserts” that 5 + 10 is equal to 15. If the Add function returns anything else Assert. IsEqual result in error and the test case will fail. After you write your test cases, you will run them to verify that everything is working correctly.

What are the three steps in a unit test? ›

The idea is to develop a unit test by following these 3 simple steps: Arrange – setup the testing objects and prepare the prerequisites for your test. Act – perform the actual work of the test. Assert – verify the result.

How do I run unit test code in Visual Studio? ›

There is a much easier way to run all tests:
  1. Install the . NET Core Test Explorer extension.
  2. Open a . NET Core test project in VS Code, or set dotnet-test-explorer. ...
  3. In . NET Test Explorer of Explorer view, all the tests will be automatically detected, and you are able to run all tests or a certain test.
31 Jan 2017

What is ClassInitialize attribute in MSTest? ›

The method decorated by [ClassInitialize] is called once before running the tests of the class. In some cases, you can write the code in the constructor of the class. The method decorated by [ClassCleanup] is called after all tests from all classes are executed.

What is AutoFixture C#? ›

AutoFixture is designed to make Test-Driven Development more productive and unit tests more refactoring-safe. It does so by removing the need for hand-coding anonymous variables as part of a test's Fixture Setup phase. Among other features, it offers a generic implementation of the Test Data Builder pattern.

How do I Create a Runsettings file? ›

Add a run settings file to your solution. In Solution Explorer, on the shortcut menu of your solution, choose Add > New Item, and select XML File. Save the file with a name such as test. runsettings.

Do unit tests run in parallel C#? ›

Unit tests run one at a time. There is no parallelism. See attached screenshot. We have directed your feedback to the appropriate engineering team for further evaluation.

How do I add a unit test project in .NET core? ›

Follow these steps to add the test project: Step 1: Right-click on the project solution and select the Add -> New Project option. Step 2: Select NUnit test project (. NET Core) and click Next.

How do I run MSTest on 64 bit? ›

How to run MSTest tests using x64 configuration Follow
  1. Set up . testsettings file (Open . testsettings | Hosts | Run Tests in 64 bit process on 64 bit machine)
  2. Point ReSharper to use it via ReSharper | Options | Unit Testing | MSTest | Select Test Run Configuration | Use this Test Run Configuration.
28 Jun 2018

How do I run MSTest EXE? ›

MSTest utility. To access the MSTest tool, add the Visual Studio install directory to the path or open the Visual Studio Group from the Start menu, and then open the Tools section to access the Visual Studio command prompt. Use the command MSTest from the command prompt.

Where is MSTest EXE located? ›

Add the folder that contains MSTest.exe to your path variable and restart the execution server. The default path is: C:\Program Files (x86)\Microsoft Visual Studio <version>\Common7\IDE.

What is the best testing framework for C#? ›

Among the top 3, xUnit is considered the best unit testing framework for C# simply because it has fewer attributes and makes the code clean and easy to maintain, it is also extensible just like NUnit.

What is MSTest Testadapter? ›

The adapter to discover and execute MSTest Framework based tests. MSTest.TestFramework. This is MSTest V2, the evolution of Microsoft's Test Framework. + To discover and execute tests install MSTest.

Why is gMock used? ›

gMock is used for creating fake objects in order to remove external dependencies for effective testing.

Is TestCafe better than selenium? ›

TestCafe has a better perspective than Selenium as it provides information and also the details about what is actually going on during the automation test with a status bar below. This actually helps the tester to make the debugging process easier.

Can a unit test be written without the NUnit framework library? ›

The NUnit Test Adapter allows you to run NUnit tests inside Visual Studio. If you do not add this component in your project you will not be able to find your tests in test Explorer. You need to install both the Libraries in the project where you are writing the test methods only.

What is the difference between JUnit and NUnit? ›

JUnit is a simple framework to write repeatable tests. It is an instance of the xUnit architecture for unit testing frameworks. On the other hand, NUnit is detailed as "An open-source unit testing framework". An evolving, open source framework designed for writing and running tests in Microsoft .

Does Visual Studio run tests in parallel? ›

Visual Studio Test Platform can run test assemblies in parallel.

How do I run MSTest in parallel? ›

The first thing you must do is define the project's parallel scope. After this, the level of parallelism, i.e. the number of tests you can run at the same time, must be identified in your AssemblyInfo. cs class. You should then add the [TestFixture] attribute to the test class.

How do I run MSTest in Jenkins? ›

To configure a MSTest installation, go to Manage Jenkins -> Configure System (or Manage Jenkins -> Global Tool Configuration in Jenkins 2.8, possibly earlier) and add a MSTest installation. Name is mandatory. If Path to MSTest is left blank, the default is MSTest.exe. MSTestRunner can be used as a build step.

Is Monodevelop better than Visual Studio? ›

Monodevelop is less stable as compared to Visual studio. It is good when dealing with small projects. Visual Studio is more stable and has the ability to deal with all types of projects whether small or large. Monodevelop is a lightweight IDE, i.e. it can also run on any system even with fewer configurations.

Can I run .NET on VS Code? ›

If you are an existing VS Code user, you can also add . NET support by installing the . NET Extension Pack, which includes these extensions: C# for Visual Studio Code.

Is Visualstudio code an IDE? ›

Visual Studio: IDE and Code Editor for Software Developers and Teams.

Is .NET Core faster than Python? ›

Contrary to Python, C# is a compiled language that requires more time and effort to write code but brings more efficiency in its performance. Furthermore, Common Language Infrastructure Framework also makes C# more speedy and offers better performance than Python has.

Can I use .NET Core and .NET framework together? ›

NET Core is portable, and can be tuned to run across different supported platforms. Depending on how you target your projects, it's possible to have . NET Core code run on the . NET Framework, Mono and Xamarin platforms, on Windows 8 and Windows Phone, and on the Universal Windows Platform (UWP).

Does net5 replace NET Core? ›

Net 5 that is Opensource and Cross-platform, which will replace . Net Framework, . Net Core and Xamarin with a single unified platform called . Net 5 Framework.

Is .NET Core multi threaded? ›

With . NET, you can write applications that perform multiple operations at the same time. Operations with the potential of holding up other operations can execute on separate threads, a process known as multithreading or free threading.

What is the difference between mono and .NET Core? ›

What is the difference between . NET Core and Mono? NET Core, which natively only allows you to build console apps and web applications, mono allows you to build many application types available in . NET Framework, including GUI-enabled desktop apps.

Does Google use .NET Core? ›

Google Cloud has recently added several new features to their platform that enable us to easily build and deploy . NET Core applications. Of particular note are: Cloud Run: Fully managed Serverless with containers.

How do you unit test methods? ›

A typical unit test contains 3 phases: First, it initializes a small piece of an application it wants to test (also known as the system under test, or SUT), then it applies some stimulus to the system under test (usually by calling a method on it), and finally, it observes the resulting behavior.

What is a unit test example? ›

A Real-world Example

The above unit test “asserts” that 5 + 10 is equal to 15. If the Add function returns anything else Assert. IsEqual result in error and the test case will fail. After you write your test cases, you will run them to verify that everything is working correctly.

How do you write unit tests in Visual Studio code? ›

Create a unit test project
  1. Start Visual Studio Code.
  2. Open the ClassLibraryProjects solution you created in Create a . NET class library using Visual Studio Code.
  3. Create a unit test project named "StringLibraryTest". .NET CLI Copy. dotnet new mstest -o StringLibraryTest. ...
  4. Add the test project to the solution. .NET CLI Copy.
25 Feb 2022

How do you unit test a class method? ›

Using Unittest
  1. Firstly, we have to import unittest as standard.
  2. Create a class called TestAdd that inherits from the TestCase class.
  3. Change the test functions into methods.
  4. Change the assertions to use the self. assertEqual() method in the TestCase class. ...
  5. Change the command-line entry point to call unittest.main()

What is unit testing C#? ›

A Unit Test is a code written by any programmer which test small pieces of functionality of big programs. Performing unit tests is always designed to be simple, A "UNIT" in this sense is the smallest component of the large code part that makes sense to test, mainly a method out of many methods of some class.

What are the 5 testing methods? ›

There are many different types of testing, but for this article we will stick to the core five components of testing:
  • 1) Unit Tests. ...
  • 2) Integration/System Tests. ...
  • 3) Functional Tests. ...
  • 4) Regression Tests. ...
  • 5) Acceptance Tests.
6 Jun 2017

What is unit test and its steps? ›

A unit test typically comprises of three stages: plan, cases and scripting and the unit test itself. In the first step, the unit test is prepared and reviewed. The next step is for the test cases and scripts to be made, then the code is tested.

What are the three steps in a unit test? ›

The idea is to develop a unit test by following these 3 simple steps: Arrange – setup the testing objects and prepare the prerequisites for your test. Act – perform the actual work of the test. Assert – verify the result.

What are the two types of unit testing? ›

There are 2 types of Unit Testing: Manual, and Automated.

Why do we write unit tests? ›

Developers write unit tests for their code to make sure that the code works correctly. This helps to detect and protect against bugs in the future. Sometimes developers write unit tests first, then write the code. This approach is also known as test-driven development (TDD).

How do you write a unit testable code? ›

To prepare your code to be testable:

Document your assumptions and exclusions. Avoid large complex classes that do more than one thing - keep the single responsibility principle in mind. When possible, use interfaces to decouple interactions and allow mock objects to be injected.

How do you write a unit test name? ›

The name of your test should consist of three parts: The name of the method being tested. The scenario under which it's being tested. The expected behavior when the scenario is invoked.

What is unit testing for dummies? ›

A unit test is a way of testing a unit - the smallest piece of code that can be logically isolated in a system. In most programming languages, that is a function, a subroutine, a method or property. The isolated part of the definition is important.

How do you manually test a unit? ›

How to perform Manual Testing
  1. Analyze requirements from the software requirement specification document.
  2. Create a clear test plan.
  3. Write test cases that cover all the requirements defined in the document.
  4. Get test cases reviewed by the QA lead.
  5. Execute test cases and detect any bugs.
11 Dec 2021

How do you write test cases? ›

What Are the Best Practices for Writing Effective Test Cases?
  1. Keep things straightforward and basic.
  2. Create reusable test scenarios.
  3. Keep the test case IDs separate.
  4. Peer review is crucial.
  5. The end-user or established requirements should be considered when writing effective test cases.
31 May 2022


1. Unit Testing - an example with MStest and Visual Studio
(Acilio Silva)
2. Unit Testing C# Code - Tutorial for Beginners
(Programming with Mosh)
3. Getting Started with Unit Testing in Visual Studio 2022 - nUnit
(Curious Drive)
4. Unit testing C# Exceptions
5. C# Unit Tests Using NUnit (.NET) (Beginner)
6. C# Unit Testing Tutorial
(Raw Coding)

Top Articles

Latest Posts

Article information

Author: Patricia Veum II

Last Updated: 11/23/2022

Views: 6130

Rating: 4.3 / 5 (44 voted)

Reviews: 91% of readers found this page helpful

Author information

Name: Patricia Veum II

Birthday: 1994-12-16

Address: 2064 Little Summit, Goldieton, MS 97651-0862

Phone: +6873952696715

Job: Principal Officer

Hobby: Rafting, Cabaret, Candle making, Jigsaw puzzles, Inline skating, Magic, Graffiti

Introduction: My name is Patricia Veum II, I am a vast, combative, smiling, famous, inexpensive, zealous, sparkling person who loves writing and wants to share my knowledge and understanding with you.