C++ UnitTest Object reference not set to an instance of an object

by boredatwork   Last Updated January 14, 2018 10:05 AM

Environment

Visual Studio 2017 15.5.3

Windows SDK 10 10.0.16299.0

I have one solution with two projects - one containing code and one with tests.

Problem

Building the solution is fine - gives no error. However when trying to run the tests I get:

[2018-01-14 10:18:22 Error] Object reference not set to an instance of an 
object.
[2018-01-14 10:18:22 Informational] ------ Load Playlist started ------
[2018-01-14 10:18:22 Informational] ========== Load Playlist finished (0:00:00,0025024) ==========
[2018-01-14 10:18:22 Informational] ------ Discover test started ------
[2018-01-14 10:18:22 Error] Object reference not set to an instance of an object.
[2018-01-14 10:18:22 Error] Object reference not set to an instance of an object.
[2018-01-14 10:18:22 Informational] ========== Discover test finished: 0 found (0:00:00,051049) ==========
[2018-01-14 10:18:22 Error] Exception has been thrown by the target of an invocation.

What I've tried

Besides googling and setting it all up again I had a friend clone the repo and run it on his machine - and it works for him. He has the same VS, SDK and exactly the same solution. We just commited it to a github and cloned it to new folders - I got the issue and he didn't.

Code

#include "CppUnitTest.h"
#include <math\Vector2.cpp>
using namespace Microsoft::VisualStudio::CppUnitTestFramework;
namespace testnamespace
{
TEST_CLASS(Vector2_test)
    {
    public:

        TEST_METHOD(Vector2_operator_add)
        {
            engine::math::Vector2 vectorA(1.0f, 2.0f);
            engine::math::Vector2 vectorB(3.0f, 4.0f);
            engine::math::Vector2 actualVector = vectorA + vectorB;

            Assert::AreEqual(4.f, actualVector.x);
            Assert::AreEqual(6.f, actualVector.y);

        }

    };
}
Tags : c++ unit-testing


Related Questions


What is IBM's CUPRIMDS?

Updated February 18, 2017 10:05 AM

What does stubbing mean in programming?

Updated March 03, 2017 13:05 PM

Integration tests, but how much?

Updated February 28, 2017 08:05 AM

i want a postman's counterpart for mobile developers

Updated December 05, 2017 07:05 AM

How to manage non-unit tests in a project?

Updated April 26, 2017 14:05 PM