简体   繁体   中英

Visual Build Pro 9 fails to build Unit Tests that use PrivateObject

I've recently switched from Visual Build Pro 8 to Visual Build Pro 9, and am having issues with building certain test projects. This appears to be related to various unit tests having to use the PrivateObject class in order to test private methods, something which I cannot change.

The projects in question throw the following (example) error:

RetrieveXmlControllerTest.cs(22,9): error CS0246: The type or namespace name 'RetrieveXmlController_Accessor' could not be found (are you missing a using directive or an assembly reference?) [C:\..\CorrectSubsystemTests.csproj]

which refers to the following code:

_targetAccessor = new RetrieveXmlController_Accessor(new PrivateObject(_target));

I've tried adding the Microsoft UnitTesting dll as a DeploymentItem (like so) but this isn't helping either.

[TestInitialize]
[DeploymentItem("Microsoft.VisualStudio.TestTools.UnitTesting.dll")]
public void Initialise() { // Blah Blah Blah // }

The project still builds correctly if I run it through Visual Build Pro 8, but I don't understand how. Does anyone have any ideas?

The only solution I have found is to remove all Accessors from the unit tests and replaced them with calls to PrivateObject.

So the RetrieveXmlController_Accessor is replaced by a PrivateObject, the PrivateObject is initialised like so:

_target = new RetrieveXmlController(_mockView.Object, _mockArisingFactory.Object, _mockFileHandler.Object);

And then the PrivateObject methods are used in place of the direct access that _Accessor provides.

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