2017-12-08 9 views
1

私のC++プロジェクトをVisual Studioで単体テストしたいと思います。私のテストプロジェクトへのパスを含めるように私のプロジェクトからフォルダを追加した後にテストをコンパイルしようとしたとき、私はリンカエラーを取得:Visual Studio C++でユニットテスト中にリンカエラーが発生しました

Severity Code Description Project File Line Suppression State 
Error LNK2019 unresolved external symbol "public: __thiscall Piece::Piece(enum Color)" ([email protected]@[email protected]@@@Z) referenced in function "public: __thiscall Bishop::Bishop(enum Color)" ([email protected]@[email protected]@@@Z) ChessPlusPlus-Tests D:\Documents\Projects\ChessPlusPlus\ChessPlusPlus-Tests\BishopTests.obj 1 
Error LNK2019 unresolved external symbol "public: __thiscall Board::~Board(void)" ([email protected]@[email protected]) referenced in function "public: void __thiscall ChessPlusPlusTests::BishopTests::ValidMovesTest(void)" ([email protected]@[email protected]@QAEXXZ) ChessPlusPlus-Tests D:\Documents\Projects\ChessPlusPlus\ChessPlusPlus-Tests\BishopTests.obj 1 
Error LNK2019 unresolved external symbol "public: void __thiscall Board::placePieceAt(class Piece * const,struct Position)" ([email protected]@@[email protected]@[email protected]@@Z) referenced in function "public: void __thiscall ChessPlusPlusTests::BishopTests::ValidMovesTest(void)" ([email protected]@[email protected]@QAEXXZ) ChessPlusPlus-Tests D:\Documents\Projects\ChessPlusPlus\ChessPlusPlus-Tests\BishopTests.obj 1 
Error LNK2001 unresolved external symbol "public: virtual class std::vector<struct Position,class std::allocator<struct Position> > __thiscall Bishop::getMovesFor(struct Position,class Board &)" ([email protected]@@[email protected]@@[email protected]@@@[email protected]@@[email protected]@[email protected]@[email protected]@@Z) ChessPlusPlus-Tests D:\Documents\Projects\ChessPlusPlus\ChessPlusPlus-Tests\BishopTests.obj 1 
Error LNK2001 unresolved external symbol "public: virtual class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > __thiscall Bishop::toString(void)" ([email protected]@@[email protected][email protected]@[email protected]@[email protected]@[email protected]@[email protected]@XZ) ChessPlusPlus-Tests D:\Documents\Projects\ChessPlusPlus\ChessPlusPlus-Tests\BishopTests.obj 1 
Error LNK2001 unresolved external symbol "public: virtual class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > __thiscall Bishop::toShortString(void)" ([email protected]@@[email protected]?$c[email protected]@[email protected]@[email protected]@[email protected]@[email protected]@XZ) ChessPlusPlus-Tests D:\Documents\Projects\ChessPlusPlus\ChessPlusPlus-Tests\BishopTests.obj 1 

私のテストのソースコード:

#include "stdafx.h" 
#include "CppUnitTest.h" 
#include "Bishop.h" 
#include "Board.h" 
#include "TestUtils.h" 

using namespace Microsoft::VisualStudio::CppUnitTestFramework; 

namespace ChessPlusPlusTests 
{ 
    TEST_CLASS(BishopTests) 
    { 
    public: 

     TEST_METHOD(ValidMovesTest) 
     { 
      // Arrange 
      Board board{}; 
      Bishop *piece = new Bishop{ Color::WHITE }; 
      Position pos{ 3,3 }; 
      board.placePieceAt(piece, pos); 

      // Act 
      auto validPositions = piece->getMovesFor(pos, board); 

      // Assert 
      TestUtils::AssertPositions(validPositions, { 
       0,0,0,0,0,0,0,1, 
       1,0,0,0,0,0,1,0, 
       0,1,0,0,0,1,0,0, 
       0,0,1,0,1,0,0,0, 
       0,0,0,0,0,0,0,0, 
       0,0,1,0,1,0,0,0, 
       0,1,0,0,0,1,0,0, 
       1,0,0,0,0,0,1,0, 
      }); 
     } 

    }; 
} 

をインクルードパスのを追加することなく、ヘッダファイルがメインプロジェクトにインクルードパスに依存しているため、テストプロジェクトはコンパイルされません。

メインプロジェクトはうまくコンパイルされます。

誰かが間違っていることを理解するのを助けることができますか?

ありがとうございます!

+0

あなたは私はあなたが何を意味するかわからない – Naidu

+0

プロジェクトのプロパティで静的LIBSとそのパスを追加しました。私はテストプロジェクトへの参照としてメインプロジェクトを追加し、標準ライブラリのみを使用します。 –

答えて

関連する問題