Power up your build
As powershell keeps gaining popularity in the Microsoft world, it’s became a common task to define the build process in a PS scripts.
One example for such use is in the new vNext scriptable build. In each vNext task the build parameters are delegated from the UI (task.json) to the powershell script where they are validated, processed and eventually are passed to the appropriate executable.
While TFS, Nant, MSBuild… have custom Typemock actions that are provided, powershell users can benefit powershell’s ability to use .Net assemblies to call Typemock code directly.
In order to incorporate Typemock into any type of build, 3 actions need to be performed:
- Register – In case Typemock is not Installed on the build machine (AutoDeploy).
- Start – Typemock is to be turned on before tests execution.
- Stop – Typemock is to be shut down after tests execution.
To run these 3 we’ll need to load Typemock.CLI.Common.dll and use the classes RegisterInfo, StartInfo and StopInfo, respectively. Each of these classes has an execute method that should be called to start the action.
That’s how the script should look like:
# Load Typemock Assemblies $CLICommon = "$ScriptRoot\AutoDeploy\TypeMock.CLI.Common.dll" [Reflection.Assembly]::LoadFile("$CLICommon") $Configuration = "$ScriptRoot\AutoDeploy\Configuration.dll" [Reflection.Assembly]::LoadFile("$Configuration") $Integration = "$ScriptRoot\AutoDeploy\TypeMock.Integration.dll" [Reflection.Assembly]::LoadFile("$Integration") # register $RegisterInfo = new-object TypeMock.CLI.Common.TypeMockRegisterInfo $RegisterInfo.AutoDeploy = $autoDeployEnabled -eq 'True' $RegisterInfo.IsolatorRootDirectory = ".\AutoDeploy" $RegisterInfo.Company = $licenseName $RegisterInfo.License = $licenseKey $RegisterInfo.Execute() #start $StartInfo = new-object TypeMock.CLI.Common.TypeMockStartInfo $StartInfo.Execute() #Run Tests Invoke-VSTest -TestAssemblies.. #stop $StopInfo = new-object TypeMock.CLI.Common.TypeMockStopInfo $StopInfo.Execute()
The full script will be available as part of the installation in the upcoming release.