How to use VSTestTask class of Microsoft.TestPlatform.Build.Tasks package

Best Vstest code snippet using Microsoft.TestPlatform.Build.Tasks.VSTestTask

VsTestTaskTests.cs

Source:VsTestTaskTests.cs Github

copy

Full Screen

...11 public void CreateArgumentShouldAddOneEntryForCLIRunSettings()12 {13 const string arg1 = "RunConfiguration.ResultsDirectory=Path having Space";14 const string arg2 = "MSTest.DeploymentEnabled";15 var vstestTask = new VSTestTask { VSTestCLIRunSettings = new string[2] };16 vstestTask.VSTestCLIRunSettings[0] = arg1;17 vstestTask.VSTestCLIRunSettings[1] = arg2;18 19 // Add values for required properties.20 vstestTask.TestFileFullPath = "abc";21 vstestTask.VSTestFramework = "abc";22 var result = vstestTask.CreateArgument().ToArray();23 // First, second and third args would be --framework:abc, testfilepath and -- respectively.24 Assert.AreEqual($"\"{arg1}\"", result[3]);25 Assert.AreEqual($"{arg2}", result[4]);26 }27 [TestMethod]28 public void CreateArgumentShouldPassResultsDirectoryCorrectly()29 {30 const string resultsDirectoryValue = @"C:\tmp\Results Directory";31 var vstestTask = new VSTestTask { VSTestResultsDirectory = resultsDirectoryValue };32 // Add values for required properties.33 vstestTask.TestFileFullPath = "abc";34 vstestTask.VSTestFramework = "abc";35 var result = vstestTask.CreateArgument().ToArray();36 Assert.AreEqual($"--resultsDirectory:\"{resultsDirectoryValue}\"", result[1]);37 }38 [TestMethod]39 public void CreateArgumentShouldNotSetConsoleLoggerVerbosityIfConsoleLoggerIsGivenInArgs()40 {41 var vstestTask = new VSTestTask { VSTestVerbosity = "diag" };42 // Add values for required properties.43 vstestTask.TestFileFullPath = "abc";44 vstestTask.VSTestFramework = "abc";45 vstestTask.VSTestLogger = "Console;Verbosity=quiet";46 var allArguments = vstestTask.CreateArgument().ToArray();47 Assert.IsNull(allArguments.FirstOrDefault(arg => arg.Contains("--logger:Console;Verbosity=normal")));48 Assert.IsNotNull(allArguments.FirstOrDefault(arg => arg.Contains("--logger:Console;Verbosity=quiet")));49 }50 [TestMethod]51 public void CreateArgumentShouldSetConsoleLoggerVerbosityToNormalIfConsoleLoggerIsNotGivenInArgsAndVerbosityIsn()52 {53 var vstestTask = new VSTestTask { VSTestVerbosity = "n" };54 // Add values for required properties.55 vstestTask.TestFileFullPath = "abc";56 vstestTask.VSTestFramework = "abc";57 var allArguments = vstestTask.CreateArgument().ToArray();58 Assert.IsNotNull(allArguments.FirstOrDefault(arg => arg.Contains("--logger:Console;Verbosity=normal")));59 }60 [TestMethod]61 public void CreateArgumentShouldSetConsoleLoggerVerbosityToNormalIfConsoleLoggerIsNotGivenInArgsAndVerbosityIsnormal()62 {63 var vstestTask = new VSTestTask { VSTestVerbosity = "normal" };64 // Add values for required properties.65 vstestTask.TestFileFullPath = "abc";66 vstestTask.VSTestFramework = "abc";67 var allArguments = vstestTask.CreateArgument().ToArray();68 Assert.IsNotNull(allArguments.FirstOrDefault(arg => arg.Contains("--logger:Console;Verbosity=normal")));69 }70 [TestMethod]71 public void CreateArgumentShouldSetConsoleLoggerVerbosityToNormalIfConsoleLoggerIsNotGivenInArgsAndVerbosityIsd()72 {73 var vstestTask = new VSTestTask { VSTestVerbosity = "d" };74 // Add values for required properties.75 vstestTask.TestFileFullPath = "abc";76 vstestTask.VSTestFramework = "abc";77 var allArguments = vstestTask.CreateArgument().ToArray();78 Assert.IsNotNull(allArguments.FirstOrDefault(arg => arg.Contains("--logger:Console;Verbosity=normal")));79 }80 [TestMethod]81 public void CreateArgumentShouldSetConsoleLoggerVerbosityToNormalIfConsoleLoggerIsNotGivenInArgsAndVerbosityIsdetailed()82 {83 var vstestTask = new VSTestTask { VSTestVerbosity = "detailed" };84 // Add values for required properties.85 vstestTask.TestFileFullPath = "abc";86 vstestTask.VSTestFramework = "abc";87 var allArguments = vstestTask.CreateArgument().ToArray();88 Assert.IsNotNull(allArguments.FirstOrDefault(arg => arg.Contains("--logger:Console;Verbosity=normal")));89 }90 [TestMethod]91 public void CreateArgumentShouldSetConsoleLoggerVerbosityToNormalIfConsoleLoggerIsNotGivenInArgsAndVerbosityIsdiag()92 {93 var vstestTask = new VSTestTask { VSTestVerbosity = "diag" };94 // Add values for required properties.95 vstestTask.TestFileFullPath = "abc";96 vstestTask.VSTestFramework = "abc";97 var allArguments = vstestTask.CreateArgument().ToArray();98 Assert.IsNotNull(allArguments.FirstOrDefault(arg => arg.Contains("--logger:Console;Verbosity=normal")));99 }100 [TestMethod]101 public void CreateArgumentShouldSetConsoleLoggerVerbosityToNormalIfConsoleLoggerIsNotGivenInArgsAndVerbosityIsdiagnostic()102 {103 var vstestTask = new VSTestTask { VSTestVerbosity = "diagnostic" };104 // Add values for required properties.105 vstestTask.TestFileFullPath = "abc";106 vstestTask.VSTestFramework = "abc";107 var allArguments = vstestTask.CreateArgument().ToArray();108 Assert.IsNotNull(allArguments.FirstOrDefault(arg => arg.Contains("--logger:Console;Verbosity=normal")));109 }110 [TestMethod]111 public void CreateArgumentShouldSetConsoleLoggerVerbosityToQuietIfConsoleLoggerIsNotGivenInArgsAndVerbosityIsq()112 {113 var vstestTask = new VSTestTask { VSTestVerbosity = "q" };114 // Add values for required properties.115 vstestTask.TestFileFullPath = "abc";116 vstestTask.VSTestFramework = "abc";117 var allArguments = vstestTask.CreateArgument().ToArray();118 Assert.IsNotNull(allArguments.FirstOrDefault(arg => arg.Contains("--logger:Console;Verbosity=quiet")));119 }120 [TestMethod]121 public void CreateArgumentShouldSetConsoleLoggerVerbosityToQuietIfConsoleLoggerIsNotGivenInArgsAndVerbosityIsquiet()122 {123 var vstestTask = new VSTestTask { VSTestVerbosity = "quiet" };124 // Add values for required properties.125 vstestTask.TestFileFullPath = "abc";126 vstestTask.VSTestFramework = "abc";127 var allArguments = vstestTask.CreateArgument().ToArray();128 Assert.IsNotNull(allArguments.FirstOrDefault(arg => arg.Contains("--logger:Console;Verbosity=quiet")));129 }130 [TestMethod]131 public void CreateArgumentShouldSetConsoleLoggerVerbosityToMinimalIfConsoleLoggerIsNotGivenInArgsAndVerbosityIsm()132 {133 var vstestTask = new VSTestTask { VSTestVerbosity = "m" };134 // Add values for required properties.135 vstestTask.TestFileFullPath = "abc";136 vstestTask.VSTestFramework = "abc";137 var allArguments = vstestTask.CreateArgument().ToArray();138 Assert.IsNotNull(allArguments.FirstOrDefault(arg => arg.Contains("--logger:Console;Verbosity=minimal")));139 }140 [TestMethod]141 public void CreateArgumentShouldSetConsoleLoggerVerbosityToMinimalIfConsoleLoggerIsNotGivenInArgsAndVerbosityIsminimal()142 {143 var vstestTask = new VSTestTask { VSTestVerbosity = "minimal" };144 // Add values for required properties.145 vstestTask.TestFileFullPath = "abc";146 vstestTask.VSTestFramework = "abc";147 var allArguments = vstestTask.CreateArgument().ToArray();148 Assert.IsNotNull(allArguments.FirstOrDefault(arg => arg.Contains("--logger:Console;Verbosity=minimal")));149 }150 [TestMethod]151 public void CreateArgumentShouldPreserveWhiteSpaceInLogger()152 {153 var vstestTask = new VSTestTask();154 155 // Add values for required properties.156 vstestTask.TestFileFullPath = "abc";157 vstestTask.VSTestFramework = "abc";158 vstestTask.VSTestLogger = "trx;LogFileName=foo bar.trx";159 var allArguments = vstestTask.CreateArgument().ToArray();160 Assert.IsNotNull(allArguments.FirstOrDefault(arg => arg.Contains("--logger:\"trx;LogFileName=foo bar.trx\"")));161 }162 [TestMethod]163 public void CreateArgumentShouldAddOneCollectArgumentForEachCollect()164 {165 var vstestTask = new VSTestTask { VSTestCollect = new string[2] };166 // Add values for required properties.167 vstestTask.TestFileFullPath = "abc";168 vstestTask.VSTestFramework = "abc";169 vstestTask.VSTestCollect[0] = "name1";170 vstestTask.VSTestCollect[1] = "name 2";171 var allArguments = vstestTask.CreateArgument().ToArray();172 Assert.IsNotNull(allArguments.FirstOrDefault(arg => arg.Contains("--collect:name1")));173 Assert.IsNotNull(allArguments.FirstOrDefault(arg => arg.Contains("--collect:\"name 2\"")));174 }175 }176}...

Full Screen

Full Screen

BookTests.cs

Source:BookTests.cs Github

copy

Full Screen

...24 Assert.Equal('B', result.Letter);25 }26 // Throwing Error27 /**28 /usr/local/share/dotnet/sdk/3.1.404/Microsoft.TestPlatform.targets(32,5): error MSB4181: The "Microsoft.TestPlatform.Build.Tasks.VSTestTask" task returned false but did not log an error. [/Users/rpaixao/Other/pluralsight/c#fundementals/gradebook/test/GradeBook.Tests/GradeBook.Tests.csproj]29 */3031 // [Fact]32 // public void BookDisallowsInvalidGrades()33 // {34 // // arrange35 // var book = new Book("");36 // book.AddGrade(105.0);37 // book.AddGrade(90.0);3839 // // act40 // var result = book.GetStatistics();4142 // // assert ...

Full Screen

Full Screen

VSTestTask

Using AI Code Generation

copy

Full Screen

1using Microsoft.TestPlatform.Build.Tasks;2{3 {4 public static void Main(string[] args)5 {6 VSTestTask task = new VSTestTask();7 task.TestAssembly = "test.dll";8 task.VSTestVersion = "15.0";9 task.RunSettings = "runsettings.runsettings";10 task.VSTestLogger = "trx";11 task.UseNewCollector = true;12 task.Execute();13 }14 }15}16using Microsoft.Build.Utilities;17using Microsoft.Build.Framework;18using Microsoft.VisualStudio.TestPlatform.Build;19{20 {21 public static void Main(string[] args)22 {23 VSTestTask task = new VSTestTask();24 task.TestAssembly = "test.dll";25 task.VSTestVersion = "15.0";26 task.RunSettings = "runsettings.runsettings";27 task.VSTestLogger = "trx";28 task.UseNewCollector = true;29 task.Execute();30 }31 }32}33using Microsoft.TestPlatform.Build.Tasks;34{35 {36 public static void Main(string[] args)37 {38 VSTestTask task = new VSTestTask();39 task.TestAssembly = "test.dll";40 task.VSTestVersion = "15.0";41 task.RunSettings = "runsettings.runsettings";42 task.VSTestLogger = "trx";43 task.UseNewCollector = true;44 task.Execute();45 }46 }47}48using Microsoft.Build.Utilities;49using Microsoft.Build.Framework;50using Microsoft.VisualStudio.TestPlatform.Build;51{52 {53 public static void Main(string[] args)54 {55 VSTestTask task = new VSTestTask();56 task.TestAssembly = "test.dll";57 task.VSTestVersion = "15.0";58 task.RunSettings = "runsettings.runsettings";59 task.VSTestLogger = "trx";60 task.UseNewCollector = true;61 task.Execute();62 }63 }64}

Full Screen

Full Screen

VSTestTask

Using AI Code Generation

copy

Full Screen

1using System;2using System.Collections.Generic;3using System.Linq;4using System.Text;5using System.Threading.Tasks;6using Microsoft.Build.Framework;7using Microsoft.Build.Utilities;8using Microsoft.TestPlatform.Build.Tasks;9{10 {11 public override bool Execute()12 {13 VSTestTask task = new VSTestTask();14 task.VSTestPath = "C:\\Program Files (x86)\\Microsoft Visual Studio\\2017\\Enterprise\\Common7\\IDE\\CommonExtensions\\Microsoft\\TestWindow\\vstest.console.exe";15 task.TestAssembly = "C:\\Users\\v-rajnay\\Desktop\\test\\UnitTestProject1\\bin\\Debug\\UnitTestProject1.dll";16 task.Platform = "x64";17 task.BuildConfiguration = "Debug";18 task.BuildPlatform = "x64";19 task.TestAdapterPath = "C:\\Users\\v-rajnay\\Desktop\\test\\UnitTestProject1\\bin\\Debug";20 task.EnableCodeCoverage = true;21 task.RunSettingsFile = "C:\\Users\\v-rajnay\\Desktop\\test\\UnitTestProject1\\bin\\Debug\\runsettings.runsettings";22 task.Logger = "trx;LogFileName=C:\\Users\\v-rajnay\\Desktop\\test\\UnitTestProject1\\bin\\Debug\\test.trx";23 task.RunInParallel = true;24 task.VSTestConsoleParameters = "/InIsolation";25 task.TestRunTitle = "TestRunTitle";26 task.CollectDumpOn = "TestHostCrash";27 task.DumpType = "mini";28 task.DumpCollectAlways = true;29 task.DumpCollectDumpOnDataCollectors = true;30 task.DumpCollectDumpOnTestSessionEnd = true;31 task.DumpCollectDumpOnTestSessionStart = true;32 task.DumpCollectDumpOnTestHostAbort = true;33 task.DumpCollectDumpOnTestHostLaunch = true;34 task.DumpCollectDumpOnTestStart = true;35 task.DumpCollectDumpOnTestStop = true;36 task.DumpCollectDumpOnUnsuccessfulTestAttempt = true;37 task.DumpCollectDumpOnSuccessfulTestAttempt = true;38 task.DumpCollectDumpOnTestHostExit = true;

Full Screen

Full Screen

VSTestTask

Using AI Code Generation

copy

Full Screen

1using Microsoft.TestPlatform.Build.Tasks;2using Microsoft.Build.Utilities;3using Microsoft.Build.Framework;4{5 {6 public override bool Execute()7 {8 VSTestTask vstestTask = new VSTestTask();9 vstestTask.VSTestConsolePath = @"C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\Common7\IDE\CommonExtensions\Microsoft\TestWindow\vstest.console.exe";10 vstestTask.TestAssembly = @"C:\Users\test\source\repos\UnitTestProject1\UnitTestProject1\bin\Debug\UnitTestProject1.dll";11 vstestTask.EnableCodeCoverage = true;12 vstestTask.Logger = "trx";13 vstestTask.SettingsFile = @"C:\Users\test\source\repos\UnitTestProject1\UnitTestProject1\bin\Debug\UnitTestProject1.dll.runsettings";14 return vstestTask.Execute();15 }16 }17}18using Microsoft.VisualStudio.TestPlatform.TestHost;19using Microsoft.VisualStudio.TestPlatform.ObjectModel;20using Microsoft.VisualStudio.TestPlatform.ObjectModel.Client;21using Microsoft.VisualStudio.TestPlatform.ObjectModel.Logging;22using Microsoft.VisualStudio.TestPlatform.CommunicationUtilities;23using Microsoft.VisualStudio.TestPlatform.CommunicationUtilities.Interfaces;24using Microsoft.VisualStudio.TestPlatform.CommunicationUtilities.ObjectModel;25using System;26using System.Collections.Generic;27using System.Linq;28using System.Text;29using System.Threading.Tasks;30{31 {32 public static void Main(string[] args)33 {34 var testPlatform = new TestPlatform();35 var runSettings = "<RunSettings><RunConfiguration><TargetFrameworkVersion>Framework45</TargetFrameworkVersion></RunConfiguration></RunSettings>";36 var sources = new List<string> { @"C:\Users\test\source\repos\UnitTestProject1\UnitTestProject1\bin\Debug\UnitTestProject1.dll" };37 var discoverySink = new DiscoverySink();38 var discoveryEvents = new DiscoveryEvents();39 var discoveryCriteria = new DiscoveryCriteria(sources, runSettings, 1);40 testPlatform.DiscoverTests(discoveryCriteria, discoveryEvents, discoverySink);41 discoverySink.WaitForDiscoveryToComplete();42 var executionSink = new ExecutionSink();43 var executionEvents = new ExecutionEvents();

Full Screen

Full Screen

VSTestTask

Using AI Code Generation

copy

Full Screen

1using System;2using System.Collections.Generic;3using System.Linq;4using System.Text;5using System.Threading.Tasks;6using Microsoft.VisualStudio.TestTools.UnitTesting;7using Microsoft.TestPlatform.Build.Tasks;8using Microsoft.Build.Framework;9using Microsoft.Build.Utilities;10{11 {12 static void Main(string[] args)13 {

Full Screen

Full Screen

VSTestTask

Using AI Code Generation

copy

Full Screen

1using Microsoft.TestPlatform.Build.Tasks;2using Microsoft.TestPlatform.Build.Tasks.Utilities;3using Microsoft.Build.Utilities;4using Microsoft.Build.Framework;5using System;6using System.Collections.Generic;7using System.Linq;8using System.Text;9using System.Threading.Tasks;10{11 {12 static void Main(string[] args)13 {14 VSTestTask task = new VSTestTask();15 task.TestAssemblies = new ITaskItem[] { new TaskItem(@"C:\Users\test\source\repos\ClassLibrary1\ClassLibrary1\bin\Debug\ClassLibrary1.dll") };16 task.Logger = "trx";17 task.TestAdapterPath = @"C:\Users\test\source\repos\ClassLibrary1\ClassLibrary1\bin\Debug";18 task.UseNewCollector = true;19 task.VSTestVersion = "15.0";20 task.SettingsFile = @"C:\Users\test\source\repos\ClassLibrary1\ClassLibrary1\bin\Debug\testsettings.runsettings";21 task.TestPlatformVersion = "15.0";22 task.RunSettings = @"C:\Users\test\source\repos\ClassLibrary1\ClassLibrary1\bin\Debug\runsettings.runsettings";23 task.EnableCodeCoverage = true;24 task.BuildEngine = new MockBuildEngine();25 task.Execute();26 }27 }28}29using Microsoft.TestPlatform.Build.Tasks;30using Microsoft.TestPlatform.Build.Tasks.Utilities;31using Microsoft.Build.Utilities;32using Microsoft.Build.Framework;33using System;34using System.Collections.Generic;35using System.Linq;36using System.Text;37using System.Threading.Tasks;38{39 {40 static void Main(string[] args)41 {42 VSTestTask task = new VSTestTask();43 task.TestAssemblies = new ITaskItem[] { new TaskItem(@"C:\Users\test\source\repos\ClassLibrary1\ClassLibrary1\bin\Debug\ClassLibrary1.dll") };44 task.Logger = "trx";

Full Screen

Full Screen

VSTestTask

Using AI Code Generation

copy

Full Screen

1using Microsoft.TestPlatform.Build.Tasks;2using Microsoft.Build.Framework;3using Microsoft.Build.Utilities;4using System;5{6 {7 public override bool Execute()8 {9 VSTestTask task = new VSTestTask();10 task.BuildEngine = this.BuildEngine;11 task.TestAssembly = new TaskItem[] { new TaskItem(@"C:\Sample\SampleTests.dll") };12 task.Logger = "trx";13 task.SettingsFile = @"C:\Sample\Sample.runsettings";14 task.VSTestVersion = new Version(16, 0, 0);15 task.TestAdapterPath = @"C:\Sample";16 task.EnableCodeCoverage = true;17 task.TargetPlatform = "x64";18 task.TargetPlatformArchitecture = "x64";19 task.TargetFrameworkVersion = "v4.7.2";20 task.TargetFrameworkMoniker = ".NETFramework,Version=v4.7.2";21 task.TargetFramework = "Framework45";22 task.TestFilter = "TestCategory=Sample";23 task.RunSettings = "<RunSettings>...</RunSettings>";24 task.TestRunTitle = "SampleTestRun";25 task.TestRunParameters = "param1=value1;param2=value2";26 task.ExecutionSettings = "<ExecutionSettings>...</ExecutionSettings>";27 task.DiaSessionTimeout = 1000;28 task.InIsolation = true;29 task.UseNewCollector = true;30 task.TreatTestNotExecutedAs = "Warning";31 task.IgnoreTestFailures = true;32 task.RunInParallel = true;33 task.ParallelTestCount = 2;34 task.MaxCpuCount = 2;35 task.SettingsFile = @"C:\Sample\Sample.runsettings";36 task.TestAdapterPath = @"C:\Sample";37 task.EnableCodeCoverage = true;38 task.TargetPlatform = "x64";39 task.TargetPlatformArchitecture = "x64";40 task.TargetFrameworkVersion = "v4.7.2";41 task.TargetFrameworkMoniker = ".NETFramework,Version=v4.7.2";42 task.TargetFramework = "Framework45";43 task.TestFilter = "TestCategory=Sample";44 task.RunSettings = "<RunSettings>...</RunSettings>";45 task.TestRunTitle = "SampleTestRun";46 task.TestRunParameters = "param1=value1;param2=value2";

Full Screen

Full Screen

VSTestTask

Using AI Code Generation

copy

Full Screen

1using Microsoft.Build.Utilities;2using Microsoft.TestPlatform.Build.Tasks;3{4 {5 static void Main(string[] args)6 {7 VSTestTask testTask = new VSTestTask();8 testTask.TestAssembly = "C:\\Users\\test\\Desktop\\TestProject\\TestProject\\bin\\Debug\\netcoreapp3.1\\TestProject.dll";9 testTask.Logger = "trx";10 testTask.VSTestVersion = "16.0";11 testTask.TargetFrameworkVersion = "v3.1";12 testTask.VSTestConsolePath = "C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\Enterprise\\Common7\\IDE\\Extensions\\TestPlatform\\vstest.console.exe";13 testTask.BuildEngine = new MockBuildEngine();14 testTask.Execute();15 }16 }17 {18 public void LogErrorEvent(BuildErrorEventArgs e)19 {20 throw new System.NotImplementedException();21 }22 public void LogWarningEvent(BuildWarningEventArgs e)23 {24 throw new System.NotImplementedException();25 }26 public void LogMessageEvent(BuildMessageEventArgs e)27 {28 throw new System.NotImplementedException();29 }30 public void LogCustomEvent(CustomBuildEventArgs e)31 {32 throw new System.NotImplementedException();33 }34 public bool BuildProjectFile(string projectFileName, string[] targetNames, System.Collections.IDictionary globalProperties, System.Collections.IDictionary targetOutputs)35 {36 throw new System.NotImplementedException();37 }38 {39 {40 throw new System.NotImplementedException();41 }42 }43 {44 {45 throw new System.NotImplementedException();46 }47 }48 {49 {50 throw new System.NotImplementedException();51 }52 }53 {54 {55 throw new System.NotImplementedException();56 }57 }58 }59}

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Vstest automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Most used methods in VSTestTask

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful