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.

9
  • 2
    If the method is internal does this not preclude its use from the testing assembly? Commented Feb 22, 2010 at 15:47
  • 7
    I occasionally use the ForTest approach but I always find it dead ugly (adding code which provides no actual value in terms of production business logic). Usually I find I had to use the approach because the design is somwhat unfortunate (i.e. having to reset singleton instances between tests) Commented Apr 3, 2012 at 18:53
  • 2
    Tempted to downvote this - what is the difference between this hack and simply making the class internal instead of private? Well, at least with compilation conditionals. Then it gets really messy. Commented Nov 6, 2013 at 10:18
  • 8
    @CADbloke: Do you mean making the method internal rather than private? The difference is that it's obvious that you really want it to be private. Any code within your production codebase which calls a method with ForTest is obviously wrong, whereas if you just make the method internal it looks like it's fine to use. Commented Nov 6, 2013 at 10:28
  • 2
    @CADbloke: You can exclude individual methods within a release build just as easily in the same file as using partial classes, IMO. And if you do do that, it suggests that you're not running your tests against your release build, which sounds like a bad idea to me. Commented Nov 6, 2013 at 10:54