-
Notifications
You must be signed in to change notification settings - Fork 748
Inherited Test SetUp, TearDown, etc. are not executed in .NET Core if they are not public #2448
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Thanks, I think I've seen this issue in another repository, but it does belong here. Your code looks good, so I am going to mark this as a bug immediately. The reflection APIs have subtle differences between .NET Core and .NET Framework, so it is likely caused by that. We will look into it. Thanks. |
Hi @declancodes. Can you check wether making the methods public solves the problem (see #1657 for a similar issue). |
Changing those methods to public makes them called as expected - thanks for the workaround, @mikkelbu Sounds like this is the same issue, but #1657 is muddied by the fact that it references the |
If non-public setup and teardown are working in other builds, I would say there's some kind of bug here. At a minimum it should be documented. |
I have updated the title to highlight the problem. I also think this issue is more clearly documented than #1657, so I am going to close the other issue as a duplicate. |
Just looking at the code, I think the problem lies in
We only look at the methods of the base-class which have I'll try to add some tests and supply a PR. |
We now return all non-private methods from base classes instead of only all public-methods. Furthermore, when filtering with BindingFlags.NonPublic we return all non-public methods instead of all private methods. Tests have been added to ensure the behaviour is the same between regular .NET reflection and our own reflection methods. Also the test `CanGetStaticMethodsOnBase()` has been corrected and enabled. Fixes #2448
Good catch, I suspected it was in our extensions, but didn't know which one. |
I think that there is a similar problem for properties (the code in |
@rprouse - I haven't milestoned this, as I'm not sure what you'll be doing for 3.8.2. (With hindsight - maybe I shouldn't have merged either - sorry!) Will leave it with you. |
Hello All,
In trying to port some NUnit tests to .NET Core I've found that methods with
[OneTimeSetUp]
,[SetUp]
,[TearDown]
, and[OneTimeTearDown]
attributes from a base class are not being called on[Test]
s in derived classes. This is only occurring when running against .NET Core, for all versions of NUnit I've tried (3.7.1 and up).Apologies if this has been documented elsewhere (I believe I checked thoroughly...) or if I'm doing something silly here!
To reproduce:
csproj
file:Test:
EDIT: use XML, not C#, formatting for
csproj
The text was updated successfully, but these errors were encountered: