当前位置: 动力学知识库 > 问答 > 编程问答 >

c# - Getting the Compiler Error CS0122 - 'member' is inaccessible due to its protection level - while trying to access a class in a different project

问题描述:

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?

网友答案:

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

分享给朋友:
您可能感兴趣的文章:
随机阅读: