4

I am trying to get to grips with NUnit - i have installed it and run it successfully within one project. I want to keep productioncode seperate from testcode, so i write tests in a different project. The Test Project Links to the original project. (IDE C# Express 2010)

My Testcode looks like this:

using NUnit.Framework;

namespace test.Import
{
    [TestFixture]
    class XMLOpenTest
    {
        [Test]
        public void openNotAPath(){
            try
            {
                production.Import.XMLHandler.open("Not A Path");
            }
            catch
            {
                Assert.Fail("File Open Fail");
            }
        }
    }
}

I know i could resolve this by making the production.Import.XMLHandler Class public, but i dont want to change my productioncode to allow this kind of testing.

How do i get around this? Can i make changes to my testcode? Are there other good ways to seperate test and production code in two projects? Are there ressources for dummys on the internet?

Johannes
  • 6,490
  • 10
  • 59
  • 108
  • 2
    Make it `*public* class XMLOpenTest`.... it has worked for me tons of times ;) – Machinarius Dec 09 '10 at 13:45
  • @Machinarius making it public was all that I needed in may case where i was copying classes between projects with references, thx – bart Sep 16 '15 at 10:53
  • 1
    @bart The advantage of making it public is that you have it easier once. But now your class is visible from outside your assembly. That may not be what you want in the long run. If this is a proof of concept project that may still be the better solution. If this is for business purposes you should think about what others can have access to after you release it. – Johannes Sep 16 '15 at 11:22

1 Answers1

11

This is usually solved using InternalsVisibleToAttribute. See this and this.

Community
  • 1
  • 1
Anton Gogolev
  • 113,561
  • 39
  • 200
  • 288
  • Worked great. I added [assembly: InternalsVisibleTo("test")] to the Top level of production - everything is peachy now. Tanks. – Johannes Dec 09 '10 at 13:52