Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 697
Dockson Avatar asked Nov 09 '16 20:11

Dockson


People also ask

How do I run MSTest in Visual Studio?

Run tests in Test Explorer If Test Explorer is not visible, choose Test on the Visual Studio menu, choose Windows, and then choose Test Explorer (or press Ctrl + E, T). As you run, write, and rerun your tests, the Test Explorer displays the results in a default grouping of Project, Namespace, and Class.


2 Answers

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

like image 67
Rick Runowski Avatar answered Oct 26 '22 21:10

Rick Runowski


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

like image 37
Claudio Redi Avatar answered Oct 26 '22 20:10

Claudio Redi