PlatformAttribute (NUnit 2.2.2)

The Platform attribute is used to specify platforms for which a test or fixture should be run. Platforms are specified using case-insensitive string values and may be either included or excluded from the run by use of the Include or Exclude properties respectively. Platforms to be included may alternatively be specified as an argument to the PlatformAttribute constructor. In either case, multiple comma-separated values may be specified.

If a test or fixture with the Platform attribute does not satisfy the specified platform requirements it is skipped. The test does not affect the outcome of the run at all: it is not considered as ignored and is not even counted in the total number of tests. In the gui, the tree node for the test remains gray and the status bar color is not affected.

Note: In versions of NUnit prior to 2.4, these tests were shown as ignored.

Test Fixture Syntax

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

  [TestFixture]
  [Platform("NET-2.0")]
  public class DotNetTwoTests
  {
    // ...
  }
}
Imports System
Imports Nunit.Framework

Namespace Nunit.Tests

  <TestFixture(), Platform("NET-2.0")>
  Public Class DotNetTwoTests
    ' ...
  End Class
End Namespace
#using <Nunit.Framework.dll>
using namespace System;
using namespace NUnit::Framework;

namespace NUnitTests
{
  [TestFixture]
  [Platform("NET-2.0")]
  public __gc class DotNetTwoTests
  {
    // ...
  };
}

#include "cppsample.h"

namespace NUnitTests {
  // ...
}
package NUnit.Tests;

import System.*;
import NUnit.Framework.TestFixture;


/** @attribute NUnit.Framework.TestFixture() */
/** @attribute NUnit.Framework.Platform("NET-2.0") */
public class DotNetTwoTests
{
  // ...
}

Test Syntax

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

  [TestFixture]
  public class SuccessTests
  {
    [Test]
    [Platform(Exclude="Win98,WinME")]
    public void SomeTest()
    { /* ... */ }
}
Imports System
Imports Nunit.Framework

Namespace Nunit.Tests

  <TestFixture()>
  Public Class SuccessTests
    <Test(), Platform(Exclude="Win98,WinME")> Public Sub SomeTest()
      ' ...
    End Sub
  End Class
End Namespace
#using <Nunit.Framework.dll>
using namespace System;
using namespace NUnit::Framework;

namespace NUnitTests
{
  [TestFixture]
  public __gc class SuccessTests
  {
    [Test][Platform(Exclude="Win98,WinME")] void SomeTest();
  };
}

#include "cppsample.h"

namespace NUnitTests {
  // ...
}
package NUnit.Tests;

import System.*;
import NUnit.Framework.TestFixture;


/** @attribute NUnit.Framework.TestFixture() */
public class SuccessTests
{
  /** @attribute NUnit.Framework.Test() */
  /** @attribute NUnit.Framework.Platform(Exclude="Win98,WinME") */
  public void SomeTest()
  { /* ... */ }
}

Platform Specifiers

The following values are recognized as platform specifiers. They may be expressed in upper, lower or mixed case.

Notes:

  1. Includes Net-2.0
  2. Includes Net-2.0 and Net-3.0
  3. Includes Net-4.0
  4. Includes Mono-2.0
  5. Includes Mono-2.0 and Mono-3.0