Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Test project cannot find objects in the project it is testing

I'm using Visual Studio 2010 and created a bunch of unit tests.

Here is an example:

    [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.");
    }

The problem is, it says:

The type or namespace name 'ShoppingRequestDetailsData' could not be found (are you missing a using directive or an assembly reference?)

Cannot implicitly convert type 'ShoppingWithFriends.ShoppingRequestDetailsData[]' to 'ShoppingRequestDetailsData[]'

It picks up the Namespace that it's from, and I can run the tests that don't require custom classes. It's only these that are causing me problems.

Any ideas?

Thanks.

like image 941
apexdodge Avatar asked Aug 18 '11 20:08

apexdodge


People also ask

How do I test a project in Visual Studio?

Select the test project in Solution Explorer. On the Project menu, select Add Reference. In Reference Manager, select the Solution node under Projects. Select the code project you want to test, and then select OK.

How do I add a test to Xcode project?

The easiest way to add a unit test target to your project is to select the Include Tests checkbox when you create the project. Selecting the checkbox creates targets for unit tests and UI tests. To add a unit test target to an existing Xcode project, choose File > New > Target.


2 Answers

A few things to check:

First, I would double-check the reference in your project -- is it a project reference or an assembly reference? If it's an assembly reference, are you sure that it's pointing at the right version of the file? (e.g. if you renamed directories, maybe it's pointing at the old directory). To be sure, use a tool like Reflector to examine the assembly directly and make sure the type is there in the right namespace.

Second, I'm not sure if this is your problem but I had a similar issue where a namespace was not found even though there was a project reference in the same solution, types were public, etc..

It turned out that I needed to change the "Target Framework" to be ".NET Framework 4" instead of ".NET Framework 4 Client Profile". I didn't bother figuring out why this resulted in an "unknown namespace" error, but it solved my problem.

Just a couple things to check, hope it helps...

John

like image 146
JohnD Avatar answered Oct 31 '22 03:10

JohnD


Checkout class access modifier. It should be public

like image 24
John Doe Avatar answered Oct 31 '22 03:10

John Doe