Wyatt Barnett
Wyatt Barnett

Reputation: 15663

How to apply an NUnit Attribute to An Assembly

According to the documentation you can apply the NUnit timeout attribute to an assembly:

The attribute may also be specified on a fixture or assembly, in which case it indicates the default timeout for any subordinate test cases.

The challenge I am running into is that they give no indication of how to apply the attribute to an assembly on that page or anywhere else I can find in the documentations.

I tried using [SetupFixture] and decorating that with the attribute but that did not seem to take. Has anyone had any success in making something like this work?

Upvotes: 10

Views: 3165

Answers (2)

hunch_hunch
hunch_hunch

Reputation: 2331

To apply the Timeout attribute to an assembly, first add the directive using NUnit.Framework; to the assembly's AssemblyInfo.cs. Then add a line specifying the timeout:

[assembly: Timeout(1000)]

Upvotes: 9

Sam Holder
Sam Holder

Reputation: 32964

According to the MSDN page you can do this using the format you have seen in the AssemblyInfo.cs file:

[assembly: AssemblyCulture("")]

You can therefore probably use:

[assembly: NUnit.Framework.Timeout(2000)]

Although I have not tried this.

This does not need to be in the AssemblyInfo.cs, it can be in any file, and if you want to share settings across many assemblies you can define it in one GlobalAssemblyInfo.cs and then link this file into every project to use the shared assembly settings.

Upvotes: 3

Related Questions