How do I build a unit test project while running an Azure Cloud CI build through Visual Studio Online?

I have a Visual Studio solution with Azure Cloud with the following projects:

  • CloudService
  • CloudServiceRole
  • Tests

Where project Tests

is a standard MSTest project that contains unit tests for the business logic in the project CloudServiceRole

.

The code is stored in Visual Studio Online and I've hooked up the automatic CI deployment that Azure offers. When I check the code, my cloud service staging deployment is automatically updated. However, the Tests project is never built during the CI build! This, of course, means that no unit tests are run at build time, as the "run unit tests" part of the build process does not find test assemblies.

My goal is to change this so that the test project is built and all unit tests run.

Looking at the MSBuild arguments that the CI deployment process uses, it seems that only the target is being met CloudService:Publish

. The project CloudService

has nothing to do with the project Tests

, so MSBuild never creates it.

What i tried

I cannot manually add the dependency CloudService->Tests

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 the dependency CloudServiceRole->Tests

because it makes a circular dependency.

/t:Build

There was another error when instructing MSBuild to build a complete solution by manually adding a parameter :C:\a\bin\ServiceDefinition.csdef: Need to specify the physical directory for the virtual path 'Web/' of role Web.

Adding the project Tests

as a separate build target along with the solution results in building tests! However, at the same time, it disables the continuous deployment functionality:More than one solution found. Continuous Deployment skipped.

An attempt to create a fake role of Project cloud-based service, which refers to the project Tests

, but has zero items, adjusted results due to assembly errors: 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 .

+3


source to share


2 answers


You need to run Build

it Publish

separately. I faced the same issue on a VSO project (now VSTS) and this fixed it. This is because your cloud service is independent of your unit test project.

1) Visual Studio Build (or MSBuild) action with arguments /t:Build

(clean here)

2) Visual Studio Build (or MSBuild) action with arguments /t:Publish

(don't clean here)



Note: I had to run these actions separately (not /Build;Publish

), otherwise I got an error about the cloud service entry point.

Put this together from this question both here and here .

+1


source


One workaround that seems to bring results is to add a pre-MSBuild script to the build definition and explicitly build the Tests project in the script.

:: This is used as a pre-build script in Continuous Deployment builds because on their own, they do not build the Tests project.
"c:\Windows\Microsoft.NET\Framework64\v4.0.30319\MSBuild.exe" %~dp0\..\..\Tests\Tests.csproj /t:Build /p:Configuration=Debug;Platform=AnyCPU;OutDir="%~dp0\..\..\..\..\bin\\"

      



It seems to do the job, although I'm not sure what side effects I should be aware of. My main problem is that the binaries from this build end up in the same directory as the binaries from the Cloud Service build - perhaps there is some potential for conflict?

0


source







All Articles