Answers for "NUnit test syntax"

C#
0

NUnit test syntax

namespace NUnit.Tests
{
  using System;
  using NUnit.Framework;

  [TestFixture]
  public class SuccessTests
  {
    // A simple test
    [Test]
    public void Add()
    { /* ... */ }

    // A test with a description property
    [Test(Description="My really cool test")]
    public void Add()
    { /* ... */ }

    // Alternate way to specify description as a separate attribute
    [Test, Description("My really really cool test")]
    public void Add()
    { /* ... */ }

    // A simple async test
    [Test]
    public async Task AddAsync()
    { /* ... */ }

    // Test with an expected result
    [Test(ExpectedResult = 4)]
    public int TestAdd()
    {
        return 2 + 2;
    }

    // Async test with an expected result
    [Test(ExpectedResult = 4)]
    public async Task<int> TestAdd()
    {
        await ...
        return 2 + 2;
    }
  }
}
Posted by: Guest on June-24-2021

C# Answers by Framework

Browse Popular Code Answers by Language