docs
docs copied to clipboard
Attributes that don't exist on .NET Standard builds are not so noted in docs
Following a comment on issue #235, it seems as if we should have a section in the docs for each attribute (and possibly other stuff as well) that indicates which framework builds support the particular item. Priority can be given to those that do not exist in our .NET Standard builds, like TimeoutAttribute
and PlatformAttribute
.
As a possibly broader issue in the framework repo, we may want to consider whether more attributes should be supported in compilation but give a warning when used in the wrong platform. We already support a few parallelization-related attributes for compilation only, but the only warning is (I think) in the docs.
Is there any workaround? The PlatformAttribute is a real pain because obviously I want to disable tests that don't work on .NET Standard!
Not currently...
As a workaround, I suggest you simply create your own PlatformAttribute
conditionally for your .NET standard builds. Start from NUnit's own implementation but modify it so you don't use PlatformHelper, which will bring in a bunch of classes that we also do not build for .NET Standard.
Instead, create your ApplyToTest()
method to only recognize what you need for the options you are using. For example, you can handle including or excluding .NET Core, if that's what you need to do.
This is a real hack, but it's something you can do within a single application so as to keep building.
The alternative workaround, of course, is to use conditional compilation to exclude some tests.
If your tests don't work because you're targeting .NET Standard, then you would need conditional compilation with #if
even if PlatformAttribute was available.
If your tests don't work only on .NET Core, keep in mind that .NET Standard-targeted assemblies can also run against .NET Framework. What I'm trying to say is that .NET Standard is not a platform; it's a platform spec. In C# terminology, an interface rather than an implementation. PlatformAttribute
can let you ignore tests when executing on .NET Core or on .NET Framework, but .NET Standard is not a platform and no tests are ever executed "on" .NET Standard.
Just an update on the particulars: TimeoutAttribute and PlatformAttribute are now present for all platforms.