11

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

Bassie
  • 8,477
  • 7
  • 47
  • 127
Dockson
  • 482
  • 2
  • 5
  • 14

4 Answers4

20

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

palako
  • 3,229
  • 2
  • 22
  • 32
Claudio Redi
  • 65,896
  • 14
  • 126
  • 152
  • 4
    Did not know you had to explicitly add a reference through Add > Reference in solution explorer. Thanks. – Dockson Nov 09 '16 at 20:36
10

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! :)

Rick Runowski
  • 326
  • 2
  • 8
1

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.

Leslie Alldridge
  • 955
  • 1
  • 5
  • 22
0

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

JohnFF
  • 688
  • 5
  • 18