单元测试Windows商店应用程序- MSBuild, MSTest和TeamCity
本文关键字:MSTest TeamCity MSBuild Windows 应用程序 单元测试 | 更新日期: 2023-09-27 17:49:55
我正在尝试设置CI服务器(TeamCity 7)并在其上运行Windows商店应用程序的每日构建和冒烟测试。冒烟测试应该只是启动应用程序,等待5秒并退出。
我创建了MSBuild脚本来编译代码(在观看了Pluralsight关于持续集成的课程之后)。在我的解决方案中,第一个项目是空白的Windows商店应用程序,第二个是测试(单元测试库(Windows商店应用程序)-如http://msdn.microsoft.com/en-us/library/vstudio/hh440545.aspx所述)。
但是我找不到:A)如何从测试方法启动空白应用程序?B)如何在本地从msbuild脚本和TeamCity服务器上运行测试。
在Windows 8桌面使用VS 2012 Premium
下面是当前脚本:
<?xml version="1.0" encoding="utf-8"?>
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="4.0"
DefaultTargets="Compile" >
<UsingTask TaskName="MSBuild.ExtensionPack.Framework.AsyncExec"
AssemblyFile=".'Thirdparty'Tools'MSBuildAsyncExec'MSBuild.ExtensionPack.dll"/>
<UsingTask TaskName="RunAllTestsInSolution"
AssemblyFile=".'Thirdparty'Tools'MSBuildCustomTasks'RunAllTestsInSolution.dll"/>
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
</PropertyGroup>
<ItemGroup>
<BuildArtifacts Include=".'buildartifacts'"/>
<SolutionFile Include=".'Decide Now.sln"/>
</ItemGroup>
<ItemGroup>
<!-- <MSTest Include=".'Thirdparty'Tools'MSTestFramework'Microsoft.VisualStudio.TestPlatform.UnitTestFramework.dll"/>-->
<TestAssembly Include=".'buildartifacts'Tests'Tests.dll"/>
<TestResults Include=".'buildartifacts'TestResults.trx"/>
</ItemGroup>
<PropertyGroup >
<VisualStudioDir>C:'Program Files (x86)'Microsoft Visual Studio 11.0'</VisualStudioDir>
<MSTest>$(VisualStudioDir)Common7'IDE'MSTest.exe</MSTest>
</PropertyGroup>
<Target Name="Clean">
<RemoveDir Directories="@(BuildArtifacts)"/>
<!-- TODO: Clean bin, obj and AppPackage folders in Sources and Test-->
</Target>
<Target Name="Init" DependsOnTargets="Clean">
<MakeDir Directories="@(BuildArtifacts)"/>
</Target>
<Target Name="Compile" DependsOnTargets="Init">
<MSBuild Projects="@(SolutionFile)" Targets="Rebuild"
Properties="OutDir=%(BuildArtifacts.FullPath);Configuration=$(Configuration)"/>
</Target>
<Target Name="Test" DependsOnTargets="Compile">
<!-- IgnoreExitCode=”true” -->
<Exec Command='"$(MSTest)" /testcontainer:@(TestAssembly) /resultsfile:@(TestResults)'/>
<Message Text='##teamcity[importData type="mstest" path="@(TestResults)"]'/>
</Target>
</Project>
下面是测试示例
using Microsoft.VisualStudio.TestPlatform.UnitTestFramework;
namespace Decide_Now{
[TestClass]
public class SmokeTest{
[TestMethod]
public void RunOnce(){
int x = 1;
int y = 2;
Assert.AreEqual( 3, x + y );
/*App.Start( null );
//var mainPage = new MainPage();
Task.Delay( 3000 ).Wait();
App.Current.Exit();*/
}
}
}
正如你在注释中看到的,我尝试了几种方法,但它说:
Test:
"C:'Program Files (x86)'Microsoft Visual Studio 11.0'Common7'IDE'MSTest.exe"
/testcontainer:.'buildartifacts'Tests'Tests.dll /resultsfile:.'buildartifacts
'TestResults.trx
Microsoft (R) Test Execution Command Line Tool Version 11.0.50727.1
Copyright (c) Microsoft Corporation. All rights reserved.
Loading .'buildartifacts'Tests'Tests.dll...
Starting execution...
No tests to execute.
##teamcity[importData type="mstest" path=".'buildartifacts'TestResults.trx"]
SOS .
要启动您的appx,请查看代码@ http://social.msdn.microsoft.com/Forums/en-US/windowsgeneraldevelopmentissues/thread/a4d2fca1-4034-4cc7-a86a-6242ce1a8b16你必须意识到你的应用程序在打开后几秒钟内就会变得不活跃,因为你没有和它互动。
要运行Windows8存储单元测试,请使用vstest.console.exe而不是mstest.exe。vest .console.exe是VS2012中新的单元测试执行器。