Document your code
Every project on GitHub comes with a version-controlled wiki to give your documentation the high level of care it deserves. It’s easy to create well-maintained, Markdown or rich text documentation alongside your code.
Sign up for free See pricing for teams and enterprisesWarnings
Sometimes - especially in integration testing - it's desirable to give a warning message but continue execution. Beginning with release 3.6, NUnit supports this with the Warn
class and the Assert.Warn
method.
Syntax
// Use Warn with reversed condition
Warn.If(2+2 != 5);
Warn.If(() => 2 + 2 != 5);
Warn.If(2+2, Is.Not.EqualTo(5));
Warn.If(() => 2+2, Is.Not.EqualTo(5).After(3000));
// Use Warn with original condition
Warn.Unless(2+2 == 5);
Warn.Unless(() => 2 + 2 == 5);
Warn.Unless(2+2, Is.EqualTo(5));
Warn.Unless(() => 2+2, Is.EqualTo(5).After(3000));
// Issue a warning message
Assert.Warn("Warning message");
Each of the above items would fail. The test would continue to execute, however, and the warning messages would only be reported at the end of the test. If the test subsequently fails, the warnings will be reported along with the failure message or - in the case of Assert.Multiple
- messages.
All of the overloads above also have a variant that accepts a function, Func<string>
, that is used to build the message included with the Exception.
Note: The framework reports warnings by including information about them in the XML result that is sent to the runner in use. If you are using this facility, make sure the runner you use supports warnings. Generally, the runners released by the NUnit team after the release of the 3.6 framework will have this support. Earlier releases will not. Many third party runners will not know what to do with warnings either.
Copyright (c) 2018 The NUnit Project - Licensed under CC BY-NC-SA 4.0
Pages 270
- Home
- .NET Core and .NET Standard
- Action Attributes
- Active Attributes
- Adapter Installation
- Adapter License
- Adapter Release Notes
- Adapter Roadmap
- Adapter Source Stepping
- AdapterV2 Release Notes
- Addin Replacement in the Framework
- AllItemsConstraint
- AndConstraint
- AnyOfConstraint
- Apartment Attribute
- Architectural Overview
- Assembly Isolation
- Assert.AreEqual
- Assert.AreNotEqual
- Assert.AreNotSame
- Assert.AreSame
- Assert.Catch
- Assert.CatchAsync
- Assert.Contains
- Assert.DoesNotThrow
- Assert.DoesNotThrowAsync
- Assert.Fail
- Assert.False
- Assert.Greater
- Assert.GreaterOrEqual
- Assert.Ignore
- Assert.Inconclusive
- Assert.IsAssignableFrom
- Assert.IsEmpty
- Assert.IsInstanceOf
- Assert.IsNaN
- Assert.IsNotAssignableFrom
- Assert.IsNotEmpty
- Assert.IsNotInstanceOf
- Assert.Less
- Assert.LessOrEqual
- Assert.Negative
- Assert.NotNull
- Assert.NotZero
- Assert.Null
- Assert.Pass
- Assert.Positive
- Assert.Throws
- Assert.ThrowsAsync
- Assert.True
- Assert.Zero
- AssertionHelper
- Assertions
- AssignableFromConstraint
- AssignableToConstraint
- Assumptions
- Attribute Hierarchy
- AttributeConstraint
- AttributeExistsConstraint
- Attributes
- Author Attribute
- Best practices for XML documentation
- BinarySerializableConstraint
- Breaking Changes
- Category Attribute
- Classic Model
- Coding Standards
- Collection Assert
- CollectionContainsConstraint
- CollectionEquivalentConstraint
- CollectionOrderedConstraint
- CollectionSubsetConstraint
- CollectionSupersetConstraint
- Combinatorial Attribute
- Configuration Files
- Console Command Line
- Console Release Notes
- Console Runner
- Constraint Model
- Constraints
- Contributions
- Counting Tests
- Culture Attribute
- Custom Asserts
- Custom Attributes
- Custom Constraints
- Datapoint Attribute
- DatapointSource Attribute
- Debugger Source Stepping
- Debugging
- DefaultFloatingPointTolerance Attribute
- DelayedConstraint
- Description Attribute
- DictionaryContainsKeyConstraint
- DictionaryContainsValueConstraint
- Directory Assert
- Dynamic Test Cases Spec
- EmptyCollectionConstraint
- EmptyConstraint
- EmptyDirectoryConstraint
- EmptyStringConstraint
- EndsWithConstraint
- Engine Addins Spec
- Engine Driver Api
- Engine Extensibility
- Engine Parallel Test Execution
- EqualConstraint
- Event Listeners
- ExactCountConstraint
- ExactTypeConstraint
- Explicit Attribute
- Extended Constraint Syntax Spec
- Extending NUnit
- FalseConstraint
- File Assert
- FileOrDirectoryExistsConstraint
- Framework Api
- Framework Design
- Framework Drivers
- Framework Extensibility
- Framework Parallel Test Execution
- Framework Release Notes
- Generation of Test Names Spec
- Getting Started in Visual Studio
- Getting Started in Visual Studio for Mac
- GreaterThanConstraint
- GreaterThanOrEqualConstraint
- IApplyToContext Interface
- IApplyToTest Interface
- ICommandWrapper Interface
- IFixtureBuilder Interface
- Ignore Attribute
- IImplyFixture Interface
- Include and Exclude Attributes (Alternatives)
- Include and Exclude Attributes Spec
- Installation
- InstanceOfTypeConstraint
- Internal Trace Spec
- IParameterDataSource Interface
- ISimpleTestBuilder Interface
- Issue Tracking
- ITestBuilder Interface
- Known Problems
- LessThanConstraint
- LessThanOrEqualConstraint
- LevelOfParallelism Attribute
- License
- ListMapper
- MaxTime Attribute
- Multiple Asserts
- NaNConstraint
- NoItemConstraint
- NonParallelizable Attribute
- NonTestAssembly Attribute
- NotConstraint
- Notes Toward NUnit 4.0
- NullConstraint
- NUnit 3.0 Architecture (2009)
- NUnit Agent
- NUnit APIs
- NUnit Copyright Notice
- NUnit Documentation
- NUnit Internals
- NUnit Project XML Format
- NUnit Test Projects
- NUnit V2 Action Attributes
- NUnit Xamarin Runners
- NUnitLite Options
- NUnitLite Runner
- OneTimeSetUp Attribute
- OneTimeTearDown Attribute
- OrConstraint
- Order Attribute
- Packaging Extensions
- Packaging the Console and Engine
- Packaging the Framework
- Packaging the Installer
- Packaging the V2 Adapter
- Packaging the V3 Adapter
- Pairwise Attribute
- Parallelizable Attribute
- Parameterized Test Fixtures Spec
- Parameterized Tests
- Platform Attribute
- Platform Selection
- Pre 3.5 Release Notes
- Project Loaders
- Property Attribute
- PropertyConstraint
- PropertyExistsConstraint
- Quick Start Source Code
- Random Attribute
- Randomizer Methods
- Range Attribute
- RangeConstraint
- RegexConstraint
- Release Notes
- Repeat Attribute
- RequiresThread Attribute
- Resources
- Result Writers
- Retry Attribute
- ReusableConstraint
- Running Tests
- Runtime Selection
- SameAsConstraint
- SamePathConstraint
- SamePathOrUnderConstraint
- Samples
- Sequential Attribute
- SetCulture Attribute
- SetUICulture Attribute
- SetUp and TearDown
- SetUp and TearDown Changes
- SetUp Attribute
- SetUpFixture Attribute
- SingleThreaded Attribute
- SomeItemsConstraint
- Specifications
- StartsWithConstraint
- String Assert
- SubPathConstraint
- SubstringConstraint
- Summary Under Development
- Team Practices
- TearDown Attribute
- Template Based Test Naming
- Test Attribute
- Test Dependency Attribute Spec
- Test Discovery And Execution
- Test Engine API
- Test Filters
- Test Result XML Format
- Test Selection Language
- TestCase Attribute
- TestCaseData
- TestCaseSource Attribute
- TestContext
- TestFixture Attribute
- TestFixtureData
- TestFixtureSetUp Attribute
- TestFixtureSource Attribute
- TestFixtureTearDown Attribute
- TestGenerator Installation
- TestGenerator Release Notes
- TestGenerator Release Notes VS2015
- TestOf Attribute
- Text Output from Tests Spec
- Theory Attribute
- ThrowsConstraint
- ThrowsNothingConstraint
- Timeout Attribute
- Tips And Tricks
- TrueConstraint
- UniqueItemsConstraint
- Upgrading
- Usage
- Usage Notes
- Usage of Labels
- Values Attribute
- ValueSource Attribute
- Visual Studio Support
- Visual Studio Test Adapter
- Visual Studio Test Generator
- VS Adapter
- VS Integration
- Warnings
- Writing Engine Extensions
- XML Formats
- XmlSerializableConstraint
NUnit Project Docs
-
NUnit
-
Release Notes
-
License
- Getting Started
- Writing Tests
- Running Tests
- Extending NUnit
- Technical Notes
-
Release Notes
- NUnit Xamarin Runners
- VS Test Adapter
- VS Test Generator