Is there a way to associate Automated tests to Test Cases in Azure DevOps using VS Code? - visual-studio-code

I've been looking for an extension for VS Code that will allow the "Associate Test Case" functionality provided with Visual Studio IDE and I have had no luck.
Is there an extension that provides this functionality?
Visual Studio steps:
Open Test Explorer
Right click on a Test Case
Click on Associate To Test Case
Screenshot:

As far as I know, currently there is no such extension provided in the visual studio code to support the "Associate Test Case" function.
You could add your request for this feature on vscode UserVoice site The product team would provide the updates if they view it.

Check this extension that I have created https://github.com/JanuszNowak/janono.ado.testcase.associate.cli
it allows associating in automatic manner.
For now this is CLI, that you can run as vs-code task. Later I will create also dedicated Azure DevOps task. Visual Studio is not needed to run automatic association.
Code sample:
namespace ExampleTestProject
{
[TestClass]
[janono.ado.testcase.associate.Organization("janono-pub")]
public class UnitTest1
{
[TestMethod]
[janono.ado.testcase.associate.TestCase(5)] //<---
public void TestMethod1()
{
//yours test method content
//...
//
}
}
}

Related

Deploy Salesforce Package Using Visual Studio Code

I am new to developing for Salesforce. I have installed the Salesforce Extension Pack for Visual Studio Code. So far I have been able to create a project, authorize an org and deploy a single Apex class to a Salesforce Trailhead org.
Where I'm stuck is being able to deploy the entire package to my Salesforce org instead of just a single class. I followed the Trailhead Visual Studio Code training but it ends at deploying just a single Apex class. I've search but can't find anything that answers my question.
First you have to create Project with Manifest in Vs Code . After the update add all the class and other things to Vs code . Now update the package.xml file . You got in force-app in vs code. After then you can deploy it to org by clicking on right button .
You can right click your package file in the Explorer and select 'SFDX Deploy Source in Manifest to Org':
Alternatively, deploy from the command line with
> sfdx force:source:deploy -x path/to/package.xml
You can check docs for the CLI commands here:
https://developer.salesforce.com/docs/atlas.en-us.sfdx_cli_reference.meta/sfdx_cli_reference/cli_reference_force_source.htm#cli_reference_force_source_deploy

Is there a way to associate Selenium test with an Azure DevOps test case?

What I'm aiming for is closing the loop on test coverage.
My goal would be:
Define test cases with PM and list them out under a Test Plan in Azure DevOps.
Associate Selenium tests in Visual Studio with specific test case(s).
When the release pipeline runs the UI test, I would expect to see on the dashboard the % of test cases that passed/failed or were not even associated.
Is that even possible?
Check the following link:
https://learn.microsoft.com/en-us/azure/devops/test/associate-automated-test-with-test-case?view=azure-devops
Coded UI test, Selenium tests, and unit tests written using Version 1
of the MSTest framework can be associated with a test case.
The process to associate an automated test with a test case is:
Create a test project containing your automated test.
Check your test project into an Azure DevOps repository.
Create a build pipeline for your project, ensuring that it contains the automated test.
Use Visual Studio Enterprise or Professional 2017 or a later version to associate the automated test with a test case. The test case must have been added to a test plan that uses the build you just defined.
Check this extension that I have created https://github.com/JanuszNowak/janono.ado.testcase.associate.cli . It allows associating in automatic manner. So if yours selenium test are using xunit, nunit or mstest you can associate them automatically.
Code sample:
namespace ExampleTestProject
{
[TestClass]
[janono.ado.testcase.associate.Organization("janono-pub")]
public class UnitTest1
{
[TestMethod]
[janono.ado.testcase.associate.TestCase(5)] //<---
public void TestMethod1()
{
//yours test method content
//...
//
}
}
}

Example creating a VSTS build extension using c#

I'd like to put together some VSTS build / release management extensions in C#, although I can find some generic examples using PowerShell it would be handy to have some examples in C#.
Could anyone point me at a C# VSTS extension example please?
Regarding build task extension, you can specify the C# application, such as console application:
"execution": {
//"PowerShell3": {
// "target": "Hello.ps1",
// "argumentFormat": ""
//}
"Process": {
"target": "..\\ConsoleApplication1.exe",
"argumentFormat": "$(ConnectedServiceName) $(currentDirectory) $(ApiPortalName)"
}
}
However the Task SDK are Typescript and PowerShell, so you can’t use the SDK in your application directly, also the newest schema has removed the extra schema info (check remove extra schema info #308), so NodeJS and PowerShell are the recommended way.
Look at the source of GitVersion. The authors have wrote a TFS/VSTS task associated with it. The core of the tool is pure C#.
Here's the code of their TFS Task
https://github.com/GitTools/GitVersion/tree/master/src/GitVersionTfsTask
Here is the task you'd use inside your builds
https://marketplace.visualstudio.com/items?itemName=gittools.gitversion#overview

How to differentiate TFS Builds and manual builds using macros in Post build event

In TFS post build script of a .proj file I want to find whether the project build is happening through TFS triggered build or manually triggered build.
Can someone suggest me how to do this using macros in Post Build event.
Short answer: you can make use of the IsDesktopBuild MSBUILD property within your csproj file to differentiate between TFS and local build.
Long Answer:
Developer or Team Build?
To differentiate the build environments we have to implement a mechanism that detects in which environment the build is being executed. In other words, we need to know if we running a local build that is executed by the developer or a team build running on the build server.
In fact, there are 3 different build environments we need to consider:
· Visual Studio Build – a build executed by a developer, on their own development machine inside the Visual Studio IDE
· Team Build – a build executed by TFS (manually or scheduled), on the build.
· Desktop Build – a build explicitly executed manually, on the development workstation using the command 'msbuild.exe tfsbuild.proj'.
A ‘DesktopBuild’ and a ‘TeamBuild’ are very similar in nature except that ‘DesktopBuild’ does not perform a ‘GetLatest’ function from source repository, will not ‘Label’ the source tree and will not determine the change set.
When using MSBUILD tasks (as we will use primarily in following sections), one common way to achieve this is to use the ‘IsDesktopBuild’ and ‘BuildingSolutionFile’ properties as conditions to test in the tasks.The ‘IsDesktopBuild’ property is declared in the ‘Microsoft.TeamFoundationBuild.targets’. The ‘BuildingSolutionFile’ property is declared and assigned automatically by MSBUILD.
The following table lists the values of each of these properties in each of the build environments.
Environment IsDesktopBuild BuildingSolutionFile
Visual Studio Build (empty) (empty)
Desktop Build true true
Team Build false true
One caveat with using the ‘IsDesktopBuild’ property is that it is not defined in many target files by default. This property will have an ‘empty’ value in a Visual Studio build, so we initialize it to a value of ‘true’ as the default value. Therefore we need to be explicitly define it in all MSBUILD target files where it will be tested.
We simply add the following element to all target files where we need to differentiate between a build on the development machine and a build on the build server (within the first section).
<IsDesktopBuild Condition="'$(IsDesktopBuild)' == ''">true</IsDesktopBuild>
Update: thank you #dbardakov. Starting VS 2012 we can use the property to find if the build is happening within Visual Studio:
BuildingInsideVisualStudio
MSDN SOURCE - for BuildingInsideVisualStudio
MSDN SOURCE

VSIX extension for workflow - what type of Asset?

I'm working on a Visual Studio extension which will contain some workflows for database and code generation. One assembly named MyActivities contains some implementations of NativeActivity which are then used in XAML workflows like this:
<Sequence xmlns:my="clr-namespace:MyActivities;assembly=MyActivities">
<my:MyActivity CsdlInput="[Csdl]" SsdlOutput="[Ssdl]"/>
...
This is very similar to what the Entity Database Generation Power Pack does for Visual Studio 2010. However, our extension will be for VS2012.
Now I need a way to link this assembly to Visual Studio, so that it's available when the workflow executes. I tried creating a VSIX extension and adding the assembly as an Asset. I tried different Asset types, for example Assembly or MefComponent, but none worked. Visual Studio keeps telling me:
`Cannot create unknown type '{clr-namespace:MyActivities;assembly=MyActivities}MyActivity'.
What kind of Asset do I need to create a simple VSIX extension that installs my assembly so Visual Studio can use it?
I was able to achieve what I want:
In the project that uses the activity workflow, just add a reference to the assembly that contains the activity code (MyActivities in my case).
So maybe it's not necessary (or not possible) to create a VSIX extension that does what I want. But adding the reference is fine, too.