Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

C# Unit Testing in C# What To Test Isolation Testing

class must be public to unit test ?

Hi,

I had issues with xunit, seems like forgotten library in 2019... I have been testing before with MS unit test library, so decided to use this instead. However every class needs to be public to access it, so Im changing accessibility in order to follow the course... Did I missed something or its the framework difference ? Obviously changing classes to public isn't good thing to do.

2 Answers

Dane Parchment
MOD
Dane Parchment
Treehouse Moderator 11,077 Points

You are sort of correct.

You shouldn't be writing unit tests for private classes, the methods in that private class however, should be accessible via public methods and as such can be tested in that way. I am at work right now though, will add more to this answer when I get back.

thanks, Dane.

I'm kinda stuck in here, instructors MockInvader class inherits from IInvader, IInvader inherits from 2 other interfaces which are protected therefore I cannot make IInvader public for tests.