When do we need to use static test method?
Consider the following test class.
Results:
Thus both static and instance test methods are invoked.
From this results, I am wondering when we really need static test methods.
I am not 100% sure with my opinion. Please correct me if I am wrong.
Use static test methods to explicitly express our intent that the test methods don't want to use injected stuffs such as
ITestOutputHelper
because injected stuffs cannot be static.
The chained constraints that prevent static methods from participating in DI:
- Static methods can only access static members (other static methods, static fields, static properties, etc).
- Static constructor must be parameterless so it cannot be injected.
- Instance constructor cannot initialize static members.1 Reply
i'm not sure it particularly matters, they may just support static methods for the sake of completeness