Skip to content

Commit fe00ca2

Browse files
Add some documentation around [Culture] attribute (#3296)
* Add a section on culture-sensitive attributes to attributes.md. * Add culture.md under `test-authoring/` (cribbing from https://docs.nunit.org/articles/nunit/writing-tests/attributes/setculture.html). Also mention `[SetUICulture]` in attributes.md.
1 parent a052a9f commit fe00ca2

2 files changed

Lines changed: 35 additions & 0 deletions

File tree

docs/docs/comparison/attributes.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,3 +59,10 @@ Here are TUnit's equivalent attributes to other test frameworks.
5959
| [Category] | [Trait("Category","")] | [Category] | [TestCategory] |
6060
| [Property] | [Trait] | [Property] | [TestProperty] |
6161

62+
## Culture-sensitive Attributes
63+
64+
| TUnit | xUnit | NUnit | MSTest |
65+
|--------------------|-------|------------------------|--------|
66+
| [Culture("en-US")] | - | [SetCulture("en-US")] | - |
67+
| - | - | [Culture("en-US")] | - |
68+
| - | - | [SetUICulture("en-US") | - |
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# Culture
2+
3+
The `[Culture]` attribute is used to set the [current Culture](https://learn.microsoft.com/en-us/dotnet/api/system.globalization.cultureinfo.currentculture) for the duration of a test. It may be specified at the level of a test, fixture or assembly.
4+
The culture remains set until the test or fixture completes and is then reset to its original value.
5+
6+
Specifying the culture is useful for comparing against expected output
7+
that depends on the culture, e.g. decimal separators, etc.
8+
9+
Only one culture may be specified. If you wish to run the same test under multiple cultures,
10+
you can achieve the same result by factoring out your test code into a private method
11+
that is called by each individual test method.
12+
13+
## Examples
14+
15+
```csharp
16+
using TUnit.Core;
17+
18+
namespace MyTestProject;
19+
20+
public class MyTestClass
21+
{
22+
[Test, Culture("de-AT")]
23+
public async Task Test3()
24+
{
25+
await Assert.That(double.Parse("3,5")).IsEqualTo(3.5);
26+
}
27+
}
28+
```

0 commit comments

Comments
 (0)