测试项目无法在正在测试的项目中找到对象

ape*_*dge 8 c# testing unit-testing visual-studio-2010 visual-studio

我正在使用Visual Studio 2010并创建了一系列单元测试.

这是一个例子:

    [TestMethod()]
    [HostType("ASP.NET")]
    [AspNetDevelopmentServerHost("C:\\Users\\Employee\\Documents\\Code Spaces\\shopvote2\\trunk\\Web", "/Web")]
    [UrlToTest("http://localhost/Web")]
    public void GetUserDetailsTest()
    {
        api_Accessor target = new api_Accessor(); // TODO: Initialize to an appropriate value
        string username = string.Empty; // TODO: Initialize to an appropriate value
        string passhash = string.Empty; // TODO: Initialize to an appropriate value
        int requestID = 0; // TODO: Initialize to an appropriate value
        ShoppingRequestDetailsData[] expected = null; // TODO: Initialize to an appropriate value
        ShoppingRequestDetailsData[] actual;
        actual = target.GetUserDetails(username, passhash, requestID);
        Assert.AreEqual(expected, actual);
        Assert.Inconclusive("Verify the correctness of this test method.");
    }
Run Code Online (Sandbox Code Playgroud)

问题是,它说:

找不到类型或命名空间名称'ShoppingRequestDetailsData'(您是否缺少using指令或程序集引用?)

无法将类型'ShoppingWithFriends.ShoppingRequestDetailsData []'隐式转换为'ShoppingRequestDetailsData []'

它选择了它来自的命名空间,我可以运行不需要自定义类的测试.只有这些才会给我带来麻烦.

有任何想法吗?

谢谢.

Joh*_*hnD 8

要检查的一些事项:

首先,我会仔细检查项目中的引用 - 它是项目引用还是程序集引用?如果它是一个程序集引用,你确定它指向正确的文件版本吗?(例如,如果您重命名目录,可能它指向旧目录).可以肯定的是,使用像Reflector这样的工具直接检查程序集,并确保在正确的命名空间中存在类型.

其次,我不确定这是不是你的问题,但我有一个类似的问题,即使在同一个解决方案中有一个项目引用,类型是公共的等等,找不到命名空间.

事实证明,我需要将"目标框架"更改为".NET Framework 4"而不是".NET Framework 4 Client Profile".我没有理会为什么这会导致"未知命名空间"错误,但它解决了我的问题.

只需要检查几件事,希望它有所帮助......

约翰