I have a Visual Studio solution housing an Azure Cloud Service with the following projects:
- CloudService
- CloudServiceRole
- Tests
Where the Tests
project is a standard MSTest project that contains unit tests for the business logic in the CloudServiceRole
project.
The code is stored in Visual Studio Online and I have hooked up the automated CI build deployment that Azure offers. When I check in code, my staging deployment of the cloud service is automatically updated. However, the Tests project is never even built during the CI builds! This, of course, means that no unit tests run during the build as the "run unit tests" part of the build process finds no assemblies with tests.
My goal is to change this so the tests project is built and all the unit tests executed.
Looking at the MSBuild arguments that the CI deployment process uses, it appears that only the CloudService:Publish
target is executed. The CloudService
project has no dependency on the Tests
project so MSBuild never even builds the latter.
What I have tried
I cannot manually add a CloudService->Tests
dependency because when I add dependencies on projects that are not Cloud Service Role projects, I get an error during build (The item "C:\a\src\MyProject\Tests\Tests.csproj" in item list "ProjectReferenceWithConfiguration" does not define a value for metadata "Name".
) and I cannot add a CloudServiceRole->Tests
dependency because that would make a circular dependency.
Instructing MSBuild to build the full solution by manually adding a /t:Build
parameter resulted in yet another error: C:\a\bin\ServiceDefinition.csdef: Need to specify the physical directory for the virtual path 'Web/' of role Web.
Adding the Tests
project as a separate build target, alongside the solution, results in the tests getting built! However, at the same time, it disables the Continuous Deployment functionality: More than one solution found. Continuous Deployment skipped.
Trying to make a fake Cloud Service Role project that references the Tests
project but has zero instances configured results in a build error: WAT100: The following roles 'Tests.FakeRole' have an instance count of 0. Instance count of 0 is not supported in deployments to Microsoft Azure
. Attempting to disable this validation results in a build error due to a defect in the Azure SDK.