mardi 19 février 2019

LNK1120 and LNK2019 erros while trying to perform unit testing in VS 2017

I wish to unit test my code. It is a proprietary step in a task I have, the code of which I already wrote.

I am using VS Community 2017 v.15.9.7. I have followed the instructions of this site to the utmost detail, line by line: https://blogs.msdn.microsoft.com/vcblog/2017/04/19/cpp-testing-in-visual-studio/#Setup

But after all the includes I get two errors :

1) Error LNK1120 1 unresolved externals UnitTest1 \source\repos\Primes\Debug\UnitTest1.dll 1

2) Error LNK2019 unresolved external symbol "public: bool __thiscall SearchPrimes::IsPrime(int)" (?IsPrime@SearchPrimes@@QAE_NH@Z) referenced in function "public: void __thiscall UnitTest1::TestClass::IsOdd(void)" (?IsOdd@TestClass@UnitTest1@@QAEXXZ) UnitTest1 C:\Users\Velzevoul\source\repos\Primes\UnitTest1\unittest1.obj

I have tried moving files, but I thing randomly moving them around will do more harm than good. I read about including the "stdafx.h" to my "source", but that made thing worse, as more errors kept popping up.

Here are the header files of the code I wrote:

#pragma once

#include <vector>
#include "XMLParser.h"

class SearchPrimes 
{

public:
    std::vector<int> RangePrime(const std::pair<int, int>&);     
    //Setting the range to search for prime numbers, executing the algorithm

    bool IsPrime(int);  //The algorithm that checks if a number is prime
    bool IsOdd(int);    //Checking if a number if even or odd

};


#pragma once

#include <iostream>
#include <vector>


class XMLParser
{

public:

    void removeTags(std::string&);  //Removing the brackets of the tags of the .xml


    std::string openFile(std::string);  //Opening a file
    std::vector<std::string> readFile(const std::string&, std::string); 
   //Getting the text from the .xml file to a vector

    std::vector<std::pair<int, int> > stringsToInts();  
   //Finding the values of the tags that contain the ranges
   //and converting the string numbers to a vector<int>
};  

Here is the test.cpp

#include "stdafx.h"
#include "CppUnitTest.h"
#include "/Users/Velzevoul/source/repos/Primes/Primes/SearchPrimes.h"
#include "/Users/Velzevoul/source/repos/Primes/Primes/XMLParser.h"

using namespace Microsoft::VisualStudio::CppUnitTestFramework;

namespace UnitTest1
{       
    TEST_CLASS(TestClass)
    {
    public:

        TEST_METHOD(IsOdd)
        {
            SearchPrimes prime;
            Assert::IsTrue(prime.IsPrime(4));
        }

    };
}

What do I have to do in order to solve the external dependencies? The article says, that once I follow the steps I can begin. The test is in a separate project, as the article suggests. If you think that the problem may be related to my main() function, please tell me to include it. I do not right now, because it's quite lengthy.

I thank you for your time in advance!

Aucun commentaire:

Enregistrer un commentaire