Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

16
  • 99
    This should really be the accepted answer. I don't know about you guys, but when the tests are "too far" from the code they're testing I tend to get nervous. I'm all for avoiding to test anything marked as private, but too many private things might very well point to an internal class that is struggling to be extracted. TDD or no TDD, I prefer having more tests that test a lot of code, than to have few test that exercise the same amount of code. And avoiding to test internal stuff doesn't exactly help to achieve a good ratio. Commented May 28, 2012 at 7:50
  • 8
    There's a great discussion going on between @DerickBailey and Dan Tao regarding the semantic difference between internal and private and the need to test internal components. Well worth the read. Commented Jan 21, 2014 at 5:22
  • 50
    Wrapping in and #if DEBUG, #endif block will enable this option only in debug builds. Commented Feb 4, 2014 at 16:33
  • 32
    This is the correct answer. Any answer that says that only public methods should be unit tested is missing the point of unit tests and making an excuse. Functional testing is black box oriented. Unit tests are white box oriented. They should testing "units" of functionality, not just public APIs. Commented Aug 18, 2015 at 23:00
  • 20
    For .NET Core - add it to any .cs file in the app. See details here - stackoverflow.com/a/42235577/968003 Commented Nov 2, 2017 at 1:13