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# Writing Unit Tests Running Tests

Type or namespace Point could not be found.

When I try to call the Point() constructor in my PointTests unit test, I am getting CS0246 error - Type or namespace Point could not be found. Are you missing a using directive or an assembly reference? However, I have included the using TreehouseDefense; directive in my unit test file.

Here is my PointTests.cs code for reference:

using System;
using Xunit;
using TreehouseDefense;

namespace TreehouseDefense.Tests
{
    public class PointTests
    {
        [Fact]
        public void PointTest()
        {
            int x = 5;
            int y = 6;

            var point = new Point(x, y);

            Assert.Equal(x, point.X);
            Assert.Equal(y, point.Y);
        }
    }
}

1 Answer

I did some digging around and was able to figure out the issue. It boils down to the fact that the instructions in this course are outdated. Xunit is now built into Visual Studio and doesn't require an extension to be able to use it.

I fixed the error by following the instructions at https://docs.microsoft.com/en-us/visualstudio/test/getting-started-with-unit-testing?view=vs-2022&tabs=dotnet%2Cmstest to add a reference to the TreehouseDefense project. However, the workaround was a bit more convoluted than that. My Xunit project was targeting .NET Core 5.0 while the TreehouseDefense code base I downloaded targets .NET Core 4.7.~. So, I made a new project that targets .NET Core 5.0 and copied all the code for the TreehouseDefense project into that project.

(You could theoretically change the .NET Core version for the project using the options menu, but .NET Core 5.0 was not showing up as an option. Hence the need to create a new project.)

Mark Sebeck
Mark Sebeck
Treehouse Moderator 37,905 Points

Nice job figuring it out Eric. I changed your comment to an answer and made it the Best Answer.