Caves Travel Diving Graphics Mizar Texts Cuisine Lemkov Contact Map RSS Polski
Trybiks' Dive Texts Testing Visual Studio - moving coded UI tests to a new / different project results in null reference exceptions YAC Software
  Back

List

Charsets

Charts

DBExpress

Delphi

HTML

Intraweb

MSTest

PHP

Programming

R

Rhino Mocks

Software

Testing

UI Testing

VB.NET

VCL

WPF

Visual Studio - moving coded UI tests to a new / different project results in null reference exceptions
I've been reorganizing my test assemblies, basically splitting up unit / integration tests from coded UI / system tests and having different assemblies for the different types of tests (mainly due to system requirements for TFS build servers / agents). Shouldn't be too difficult - just create a new test project, move the tests there; obviously, move any other code that these tests depend on and add all the necessary assembly references.

Then I tried to run all the UI tests from the new project. But, alas, each test failed with the error 'System.NullReferenceException: Object reference not set to an instance of an object.'. This happened, in each test, on the first access to any property of a UI object...

Started digging around the web and an answer finally came up in one of the threads on MSDN, that points to another article, and explanation, here. Since it's not that easy to find (the fix doesn't seem to have anything to do with the symptoms), I thought I'd mention it again here.

Basically, all the UI test assembly references must have Copy Local set to False. After resetting this, my tests magically started working as expected!

The explanation is given in the penultimate post in the second discussion; since these kinds of conflicts can mess things up in unexpected ways, I've since added a rule to our SourceChecker program to force Copy Local to False for any references to Visual Studio assemblies.

BTW, not sure why Copy Local was set to True in one of those UI test assemblies; to make sure I have all the necessary references and switches in the new project, I just recorded an 'empty' coded UI test. After generating the code, assembly references were updated (as expected), but it looks like there's some sort of bug in Visual Studio - one of those assemblies had Copy Local set to True. And hence all the problems (and an hour or two of wasted time)...

HTH

Top

Comments
Alas!
No comments yet...

Top

Add a comment (fields with an asterisk are required)
Name / nick *
Mail (will remain hidden) *
Your website
Comment (no tags) *
Enter the text displayed below *
 

Top

Tags

Testing

UI Testing


Related pages

AssertWasCalled and Methods Called Multiple Times

AssertWas[Not]Called and Object Properties

Rhino Mocks's AssertWasNotCalled

PrivateObject and Out/ByRef parameters

PrivateObject, WithEvents, and generics

Accessing private members of base classes

PrivateObject and WithEvents

Accessing private and protected members - PrivateObject and PrivateType

VS - Test Run Error - "COM object that has been separated from its underlying RCW cannot be used"

Get the TreeViewItem for an Item in a WPF TreeView

Output in MSTest Tests (VS 2010)

Automated WPF tests and "Invalid URI: Invalid port specified."

Checking Property Change Notifications

Checking "Dangling" Event Handlers in Delphi Forms

Rhino Mocks's AssertWasCalled in VB.NET

First steps with Rhino Mocks (in VB.NET)

VS Pending Tests

Automated GUI Testing

Automated GUI Testing in VMs

Automated Testing of Window Forms

Detecting Memory Leaks with DUnit