ArticleslgStudy

computer science

NUnit

NUnit is a computer science topic covered in the lgStudy science library. This page brings together a partial reference excerpt, illustrations, worked examples, real-world applications and a short study plan, so you can understand NUnit rather than just read about it. In short: NUnit is an open-source unit testing framework for .NET, .NET Framework, and Mono. It serves the same purpose as JUnit does in the Java world, and is one of many in the xUnit family.

NUnit — main illustration
NUnit — illustration

Key takeaways

  • NUnit belongs to computer science; place it in that map before memorising details.
  • Learn the definition first, then one example that makes the definition concrete.
  • Connect NUnit to a quantity you can measure, compute or draw — that is where exam questions come from.
  • Reproduce the core statement of NUnit from memory before moving on to harder problems.

Reference excerpt

NUnit is an open-source unit testing framework for .NET, .NET Framework, and Mono. It serves the same purpose as JUnit does in the Java world, and is one of many in the xUnit family.

Features Tests can be run from a console runner, within Visual Studio through a Test Adapter, or through 3rd party runners. Tests can be run in parallel. Strong support for data driven tests. Supports multiple platforms including .NET Core, Xamarin Mobile, Compact Framework and Silverlight. Every test case can be added to one or more categories, to allow for selective running. NUnit provides a console runner (nunit3-console.exe), which is used for batch execution of tests. The console runner works through the NUnit Test Engine, which provides it with the ability to load, explore and execute tests. When tests are to be run in a separate process, the engine makes use of the nunit-agent program to run them. The NUnitLite runner may be used in situations where a simpler runner is more suitable. It allows developers to create self-executing tests.

Assertions NUnit provides a rich set of assertions as static methods of the Assert class. If an assertion fails, the method call does not return and an error is reported. If a test contains multiple assertions, any that follow the one that failed will not be executed. For this reason, it's usually best to try for one assertion per test. Nunit 3.x is supporting multiple assertions.

Classical Before NUnit 2.4, a separate method of the Assert class was used for each different assertion. It continues to be supported in NUnit, since many people prefer it. Each assert method may be called without a message, with a simple text message or with a message and arguments. In the last case the message is formatted using the provided text and arguments.

Constraint based Beginning with NUnit 2.4, a new Constraint-based model was introduced. This approach uses a single method of the Assert class for all assertions, passing a Constraint object that specifies the test to be performed. This constraint-based model is now used internally by NUnit for all assertions. The methods of the classic approach have been re-implemented on top of this new model.

Example Example of an NUnit test fixture:

The NUnit framework discovers the method ExampleTestOfNUnit.TestMultiplication() automatically by reflection.

Extensions FireBenchmarks is an addin that can record execution time of unit tests and generate XML, CSV, and XHTML performances reports with charts and history tracking. Its purpose is to help a developer or a team that work with an agile methodology to integrate performance metrics and analysis into the unit testing environment, to control and monitor the evolution of a software system in terms of algorithmic complexity and system resources load. NUnit.Forms is an expansion to the core NUnit framework and is also open source. It specifically looks at expanding NUnit to be able to handle testing user interface elements in Windows Forms. As of January 2013, Nunit.Forms is in Alpha release, and no versions have been released since May 2006. NUnit.ASP is a discontinued expansion to the core NUnit framework and is also open source. It specifically looks at expanding NUnit to be able to handle testing user interface elements in ASP.NET.

See also

Test automation List of unit testing frameworks for .NET programming languages (includes column indicating which are based on xUnit) XUnit.net JUnit

References

Bibliography Hunt, Andrew; Thomas, David (2007). Pragmatic Unit Testing in C# with NUnit, 2nd Ed. The Pragmatic Bookshelf (Raleigh), 2007. ISBN 0-9776166-7-3. Newkirk, Jim; Vorontsov, Alexei (2004). Test-Driven Development in Microsoft .NET. Microsoft Press (Redmond), 2004. ISBN 0-7356-1948-4. Hamilton, Bill (2004). NUnit Pocket Reference. O'Reilly (Cambridge), 2004. ISBN 0-596-00739-6.

External links Official website GitHub Site Launchpad Site (no longer maintained) Test-driven Development with NUnit & Test-driven.NET Archived 2008-05-15 at the Wayback Machine video demonstration NUnit.Forms home page NUnitAsp homepage Article Improving Application Quality Using Test-Driven Development provides an introduction to TDD with concrete examples using Nunit Open source tool, which can execute nunit tests in parallel Archived 2013-11-18 at the Wayback Machine Charlie Poole, co-developer Rob Prouse, co-developer Simone Busoli, co-developer

Illustrations

NUnit illustration
NUnit illustration

Worked examples

Example 1 — a first encounter with NUnit

Start with the simplest possible case. Write down what NUnit claims or describes in one sentence, then invent the smallest concrete situation in which that sentence is true. In computer science, the smallest case is usually a single object, a single equation or a single measurement. Check that every symbol or term in your sentence has a meaning in that case.

Example 2 — changing one variable

Take the situation from Example 1 and change exactly one quantity: double it, halve it, or set it to zero. Predict what should happen to NUnit before you calculate. Comparing your prediction with the result is the fastest way to find out whether you understand the idea or only the words.

Example 3 — an exam-style question

Typical questions about NUnit ask you to (a) state it precisely, (b) apply it to given data, and (c) explain a limitation. Practise writing all three answers in under five minutes; the third part is what separates a full-mark answer from an average one.

Applications of NUnit

In research
NUnit appears in computer science research whenever the underlying quantities have to be modelled precisely. Papers usually cite it as a starting assumption and then explore where it breaks down.
In technology and industry
Engineering practice reuses NUnit in design rules, simulations and safety margins. Knowing the idea lets you read a specification sheet and understand why the numbers look the way they do.
In the classroom
NUnit is common in secondary-school and first-year university syllabi. It links to neighbouring topics .NET software, Extreme programming, Free software programmed in C Sharp, so understanding it makes those chapters shorter.
In everyday life
Look for NUnit outside the textbook — in sport, cooking, traffic, electronics or the sky above you. An example you found yourself is remembered far longer than one you were given.
Ask Teacher Smith questions about this articleOpens your AI tutor with a question about “NUnit” →

How to study NUnit in 20 minutes

  1. Read the reference excerpt below once, without taking notes.
  2. Close the page and write down what NUnit means in your own words.
  3. Compare your version with the excerpt and mark what you missed.
  4. Work through the three examples above with pen and paper.
  5. Explain NUnit out loud to somebody else — or to Teacher Smith in the lgStudy chat.

Frequently asked questions

What is NUnit in simple terms?

NUnit is an open-source unit testing framework for .NET, .NET Framework, and Mono. It serves the same purpose as JUnit does in the Java world, and is one of many in the xUnit family.

Why does NUnit matter?

Because it connects several computer science ideas at once: it gives you a definition you can apply, a quantity you can calculate, and a way to check whether a result is plausible.

How should I study NUnit?

Read the excerpt, restate it from memory, then work through the examples and applications listed on this page. The five-step study plan above takes about twenty minutes.

What does this page cover?

It gives you a compact reference excerpt plus original lgStudy explanations, examples, applications and study material on NUnit.

Tags

  • .NET software
  • Extreme programming
  • Free software programmed in C Sharp
  • Software using the MIT license
  • Unit testing frameworks

Keep exploring