csoltenborn / GoogleTestAdapter

Visual studio extension that adds support for the C++ testing framework Google Test.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

NullReferenceException during test discover process

gomons opened this issue · comments

When I build my test project:

ERROR: Exception while resolving test locations and traits in C:\Siarhei.Homan\Win32\Debug\opencv_core310d.dll
System.NullReferenceException: Object reference not set to an instance of an object.
   at GoogleTestAdapter.DiaResolver.DiaResolver.GetFunctions(String symbolFilterString)
   at GoogleTestAdapter.TestCases.TestCaseResolver.FindTestCaseLocationsInBinary(String binary, List`1 testMethodSignatures, String symbolFilterString, String pathExtension)

Hi Sergey,

thanks for the report! Here are a couple of questions for the sake of narrowing down the cause:

  • Are you using traits with your tests? If this is the case: Are you using the latest traits macros file (released with version 0.7.0) or the previous one?
  • Which VS version (edition, version, and update level) are you using?
  • I assume GTA is working as expected, but you only have some tests without test locations (i.e., the test explorer does not provide links to the source location of the according tests) or traits? Only the tests contained in opencv_core310d.dll (if any) should be affected...
  • Is there any chance that you can share the solution causing that problem, such that we can reproduce it over here?

Hi Christian!

  1. I don't use traits (I believe I don't because I don't know how to use them)
  2. I use Visual Studio 2015 Community Edition with v120_xp toolset
  3. If I use opencv dll in my test application, GTA can't discover any tests. But if I remove opencv code from test - all tests discovered as expected.
  4. I attached solution example. In the example solution there is no NullReferenceException, but the problem remains - tests are not discovered and I can't use GTA. If you comment out opencv usage (lines 2 and 6 in BindTest/main.cpp), tests are discovered.

GoogleTestAdapter.zip

Hi Sergey,

thanks for the example solution! I have built that solution (although using v140_xp as toolset) and might have found the cause for your problems: Please run the test executable from the command line (which is always a good idea in case GTA has issues - see our trouble shooting section ;-) ). You will probably get windows dialogs complaining about missing dlls (in my case, openvc_core310d.dll and opencv_imgcodecs310d.dll), and if I comment out the lines you suggested, the test executable runs fine. You should be able to fix that by adding those dlls to the path (either system wide or using our Path extension option, see trouble shooting section).

However, this does not explain why our code produces a NullReferenceException, and to be honest, I don't see how this could happen when looking at the code mentioned in the exception. Would you be willing to help debug this issue, even if the above solves your concrete problem?

Thank you alot, Christian!

I'm sorry for my inattention... It's all because of my environment settings, I can run executable from Visual Studio because I use Envirement option and I just forgot about it.

I reproduced NullReferenceException. I attached modified solution. The NullReferenceException reason: not all dll dependencies satisfied. So I just added opencv_core310d.dll to build output directory. If I put other dll that needed to start application all is ok.

GoogleTestAdapter.zip

Hi Sergey,

no problem :-) I will try reproduce the NRE with your new solution soon...