简体   繁体   中英

Unit Test Adapter threw exception: System.NullReferenceException: Object reference not set to an instance of an object

I have created a test project it has a test function.

public void TestMethod1()
        {
            Logger.Instance.WriteLog("hello", false);
            int actual = Obj.Addition(4, 5);
            int expected = 9;
            Assert.AreEqual(actual, expected);
        }

i have created load test of this testmethod but when i try to execute the load test all test got failed and it show error Unit Test Adapter threw exception: System.NullReferenceException: Object reference not set to an instance of an object.

the error is dur to statement Logger.Instance.WriteLog("hello", false); if this statement is not there then load test execute successfully. logger class is just writing log in a text file.

It sounds like your Logger.Instance may be null - does this logger normally require some sort of initialization? Make sure you've initialized it properly before using it.

The stack trace should pin down exactly where the NullReferenceException is being thrown - maybe it's in Logger.WriteLog .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM