Reasoning behind public only test classes #2151
-
Hi! 👋 I've noticed that test classes have to be public. I haven't been able to find any articles/references as to why that is. I've previously worked in NUnit and have had some abstract classes that did some initial setup as well as add some initial tests Example public class TestHarness<T> {
protected T _serviceUnderTest;
public TestHarness() {
// create some tests to validate things like public functions have test coverage, etc.
}
public void Setup() {
// additional setup steps
_serviceUnderTest = AutoMock<T>();
}
} With the restriction of "public only classes", something like this isn't possible for internal classes and would like to see (if you're open for it) adding support for more than public classes |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
There's a primary reason, and then a secondary result. The primary reason is (or at least was?) that public reflection is much faster than private reflection. The secondary result (which would be a dramatic impact to us personally) is that in our acceptance tests, we often define the code we want to validate in a private class and then use our acceptance test helper to run that code. It's not run during the initial discover system because it's private, but our acceptance test helper doesn't care that it's private (which is of course required, since many of these acceptance tests by definition need to fail, because they're used to test failure conditions). We won't try to run tests from public |
Beta Was this translation helpful? Give feedback.
There's a primary reason, and then a secondary result.
The primary reason is (or at least was?) that public reflection is much faster than private reflection.
The secondary result (which would be a dramatic impact to us personally) is that in our acceptance tests, we often define the code we want to validate in a private class and then use our acceptance test helper to run that code. It's not run during the initial discover system because it's private, but our acceptance test helper doesn't care that it's private (which is of course required, since many of these acceptance tests by definition need to fail, because they're used to test failure conditions).
We won't try to run tests from pu…