Dockson
Dockson

Reputation: 562

Can't find project classes/methods in test project

In my namespace Draughts I have two projects, Draughts and Draughts.UnitTests. When I try to access Draughts methods/classes in Draughts.UnitTests it can't find anything at all. At the top of Draughts.UnitTests I put using Draughts. Any ideas?

BoardUnitTests.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Draughts;
using NUnit.Framework;

namespace Draughts.UnitTests
{
    public class BoardUnitTests
    {
        private Board GetBoard()
        {
            return true;
        }

        [Test]
        public void CheckValidBoardPosition_ValidPosition_ReturnsTrue()
        {
            Assert.AreEqual(1, 1);
        }
    }
}

In the code above it can't recognize Board which is a class I have defined in Draughts.

Here's a screenshot of my solution explorer:

enter image description here

Upvotes: 15

Views: 17675

Answers (4)

Claudio Redi
Claudio Redi

Reputation: 68440

Probably this is related to one of these things

  1. You don't have a reference to Draughts on your unit test project. Right click on the test project, then Add > Reference and select the project being tested.

  2. Classes on Draughts are not public so you can't see them outside the project they belongs to

Upvotes: 27

Leslie Alldridge
Leslie Alldridge

Reputation: 1583

I ran into a similar issue as I used dotnet cli to create a test project and .net core project. I forgot to add the test project to my solution (right click solution > add > existing project). Once I did that, everything worked. Not the answer for OP but leaving it here in hopes it might help other people in future.

Upvotes: 1

JohnFF
JohnFF

Reputation: 741

In my case it was because I had them compiling on different versions of .net

Upvotes: 0

Rick Runowski
Rick Runowski

Reputation: 355

I realize this is pretty old, but I came across this question while looking for a solution to my issue. For me it turned out that my Test project and the Tested project were on two different versions of the .NET Framework. I updated one, but forgot the other. Once I updated the test project to match the tested, everything worked like it should

Hope this helps the next person! :)

Upvotes: 11

Related Questions