title: How to link a file properly in Visual Studio to run native tests?
body: <p>I'm trying to write unit tests for my classes but I'm getting &quot;unresolved external symbol.&quot; There are no syntax errors and I have tried looking up the cause on the official Microsoft website but unfortunately it can be caused for a million different reasons. Any suggestions on what I can do or what might be causing it? This is my code:</p>
  <pre><code>// Example.h file
  #pragma once
  #include &lt;iostream&gt;
  
  using namespace std;
  
  class Example {
  public:
    int addTwoNumbers(int first, int second);
  };
  </code></pre>
  <pre><code>// Example.cpp file
  #include &quot;Example.h&quot;
  #include &lt;iostream&gt;
  
  using namespace std;
  
  int Example::addTwoNumbers(int first, int second) {
    return first + second;
  }
  </code></pre>
  <pre><code>// Test.cpp file
  #include &quot;pch.h&quot;
  #include &quot;../Project/Example.h&quot;
  #include &quot;CppUnitTest.h&quot;
  
  using namespace Microsoft::VisualStudio::CppUnitTestFramework;
  
  namespace Tests
  {
    TEST_CLASS(Tests)
    {
    public:
      TEST_METHOD(UnitTest1)
      {
        Example e;
        Assert::AreEqual(4, e.addTwoNumbers(2, 2)); // this line is causing issues
      }
    };
  }
  </code></pre>
  <p>The exact error that I'm getting:</p>
  <pre><code>Severity    Code    Description Project File    Line    Suppression State
  Error   LNK2019 unresolved external symbol &quot;public: int __thiscall Example::addTwoNumbers(int,int)&quot; (?addTwoNumbers@Example@@QAEHHH@Z) referenced in function &quot;public: void __thiscall Tests::Tests::UnitTest1(void)&quot; (?UnitTest1@Tests@1@QAEXXZ)   Tests   C:\Users\me\source\repos\Tests\Tests.obj    1   
  </code></pre>