|
|
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 |
|
Top
|
|
|