NUnit 2.5 Legacy Documentation. View NUnit 3 Documentation

CultureAttribute (NUnit 2.4.2)

The Culture attribute is used to specify cultures for which a test or fixture should be run. It does not affect the culture setting, but merely uses it to determine whether to run the test. If you wish to change the culture when running a test, use the SetCulture attribute instead.

If the specified culture requirements for a test are not met it is skipped. In the gui, the tree node for the test remains gray and the status bar color is not affected.

One use of the Culture attribute is to provide alternative tests under different cultures. You may specify either specific cultures, like "en-GB" or neutral cultures like "de".

Test Fixture Syntax

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

  [TestFixture]
  [Culture("fr-FR")]
  public class FrenchCultureTests
  {
    // ...
  }
}
Imports System
Imports Nunit.Framework

Namespace Nunit.Tests

  <TestFixture(), Culture("fr-FR")>
  Public Class FrenchCultureTests
    ' ...
  End Class
End Namespace
#using <Nunit.Framework.dll>
using namespace System;
using namespace NUnit::Framework;

namespace NUnitTests
{
  [TestFixture]
  [Culture("fr-FR")]
  public __gc class FrenchCultureTests
  {
    // ...
  };
}

#include "cppsample.h"

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

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


/** @attribute NUnit.Framework.TestFixture() */
/** @attribute NUnit.Framework.Culture("fr-FR") */
public class FrenchCultureTests
{
  // ...
}

Test Syntax

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

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

Namespace Nunit.Tests

  <TestFixture()>
  Public Class SuccessTests
    <Test(), Culture(Exclude="en,de")> 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][Culture(Exclude="en,de")] 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.Culture(Exclude=en,de") */
  public void SomeTest()
  { /* ... */ }
}

See also...