Skip to content

This is a demo application for the Microsoft .NET Core NUnit unit testing framework.

License

Notifications You must be signed in to change notification settings

scottgriv/csharp-nunit_test_demo

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation


C# Badge
GitHub Badge Email Badge BuyMeACoffee Badge
Bronze


C# NUnit Demo Application

This is a demo application for the Microsoft .NET Core NUnit unit testing framework.

  • It consists of two projects: NUnitDemo and NUnitDemo.Tests.
  • The NUnitDemo project is a simple ASP.NET Core application consisting of two class files.
  • The NUnitDemo.Tests project is a test project that contains unit tests for the NUnitDemo project.

Table of Contents

Getting Started

How to add NUnit framework to your ASP.NET Core Web API project.

  1. Create a new blank solution in Visual Studio.
  2. Create another project in the solution and select Test -> Unit Test Project (.NET Core) and name it NUnitDemo.Tests.
    • This will create a new project with a UnitTest1.cs file using the MSTest framework.
  3. Right click on the NUnitDemo.Tests project and select Manage NuGet Packages.
  4. Search for NUnit using the NuGet package manager.
  5. Install the following packages:
    • NUnit
    • NUnit3TestAdapter
  6. Click the Build menu and select Build Solution to build your project.
  7. Click the Test menu and select Run All Tests to run your tests.
  8. You should see the following output in the Test Explorer window:
Total tests: 2. Passed: 3. Failed: 0. Skipped: 0.

Passed Unit Test

Note

It doesn't matter if you use the default MSTest framework or the NUnit framework. You can use both in the same project. The important thing is that you're conducting unit tests to make your code more reliable.

Unit Testing is a pivotal part of the Test Driven Development (TDD) process. It is a software development process that relies on the repetition of a very short development cycle: requirements are turned into very specific test cases, then the software is improved to pass the new tests, only. This is opposed to software development that allows software to be added that is not proven to meet requirements.

Running the Tests

Update the following line to true in the NUnitDemo.Tests/UnitTest1.cs file to see the tests fail.

    bool breakTests = false; // To show failures in the unit tests, change this to true

Failed Unit Test

References

License

This project is released under the terms of The Unlicense, which allows you to use, modify, and distribute the code as you see fit.

  • The Unlicense removes traditional copyright restrictions, giving you the freedom to use the code in any way you choose.
  • For more details, see the LICENSE file in this repository.

Credits

Author: Scott Grivner
Email: scott.grivner@gmail.com
Website: scottgrivner.dev
Reference: Main Branch


About

This is a demo application for the Microsoft .NET Core NUnit unit testing framework.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Languages