TFS 2013 linking Test Case Associated Automation to xUnit tests - testing

I'm wondering if it is possible to link Test Cases in TFS 2013 to xUnit tests. Currently it works fine for msTest tests but once I change the method attribute from 'TestMethod' to 'Fact' and rebuild the test no longer appears when I click the Associated Automation in the Test Case to link the two together.
Has anybody any experience or answers for this?
Thanks

It is possible with the TFS API. This PowerShell script show you how to do that (see: https://blogs.msdn.microsoft.com/gautamg/2012/01/01/how-to-associate-automation-programmatically/ for reference).
# Get TC
$tfsTpc = [Microsoft.TeamFoundation.Client.TfsTeamProjectCollectionFactory]::GetTeamProjectCollection($TPC_URL)
$tms = $tfsTpc.GetService([Microsoft.TeamFoundation.TestManagement.Client.ITestManagementService])
$tp = $tms.GetTeamProject($TP_NAME)
$tc = $tp.TestCases.Find($tcId)
# Compute Automation Guid
$sha1Crypto = new-object System.Security.Cryptography.SHA1CryptoServiceProvider
[Byte[]] $bytes = New-Object Byte[] 16
[Array]::Copy($sha1Crypto.ComputeHash([System.Text.Encoding]::Unicode.GetBytes($testName)), $bytes, $bytes.Length)
# Create association
$tc.Implementation = $tp.CreateTmiTestImplementation($testName, $AUTOMATION_TYPE, $AUTOMATION_STORAGE_NAME, $automationGuid)
$tc.Save()
$automationGuid = New-Object -TypeName Guid -ArgumentList #(,$bytes)
But you will not be able to associate the execution with the Test Case in TFS.
The test must be run with MSTest V1 to log results as a valid TRX to be published in TFS through TCM.exe. Even with vstest.console.exe and the TRX logger option the xml result is not understandable by TCM.exe.
For reference see: http://bugsareinthegaps.com/uploading-automated-test-results-to-mtm-made-easy/

Related

How to read/fetch data from Oracle SQL database using PowerShell Core?

I have been researching on this for a couple of days but have been going in circles here.
I need to write a script that fetches the data from Oracle db and do something with the data. In my script I will have to fetch data multiple times.
My machine has the SQLDeveloper-21.4.3 which I got from installing InstantClient-Basic-Windows-21.3.0. I use the SQL Developer to connect to the db which is on another machine; this is how I can look into tables, views etc. of the db.
Secondly, this script will be hosted on another server that runs Windows-Server-2012-R2. I am just using my machine to write the script because I cannot use the server to do this. Therefore, I am looking for a solution that requires minimum amount of installing.
Thirdly, we do not have Oracle commercial license. This Oracle db I am trying to access is on the machine installed by a third party that installed some instruments. This company uses Oracle as they collect data on the instruments installed.
I was hoping the solution would be something similar to invoking connection to MS SQL where I downloaded module that gave cmdlets to connect to the MS SQL.
Oracle does have Oracle Modules for PowerShell but neither have I found information on how to use them nor have I understood the little information provided by Oracle on this. For this to work one of the requirement is:
A configuration file and key pair used for signing API requests, with
the public key uploaded to Oracle Cloud using Oracle Cloud
Infrastructure Console. Only the user calling the API should possess
the private key.
I don't know the heck Oracle is talking about here. Like, what is this configuration file, where is it? Where would I get the key pair from for signing API request. What is Oracle Infrastructure Console, where do I get it from? You get the idea.
Link: https://docs.oracle.com/en-us/iaas/Content/API/SDKDocs/powershell.htm
Therefore, I went the .DLL route.
This is what I have done so far:
I installed Oracle.ManagedDataAccess.Core -Version 3.21.61 from NuGet.
Unzipped the package and moved the Oracle.ManagedDataAccess.dll to the location of my script.
The code is:
$OracleDLLPath = "C:\Users\Desktop\CNC_File_Transfer_VSCode\Fastems_NicNet\Oracle.ManagedDataAccess.dll"
$datasource = " (DESCRIPTION =
(ADDRESS =
(PROTOCOL = TCP)
(HOST = 10.50.61.9)(PORT = 1521))
(CONNECT_DATA = (SERVER = DEDICATED)
(SERVICE_NAME = Fa1)
(FAILOVER_MODE = (TYPE = SELECT)
(METHOD = BASIC)
(RETRIES = 180)
(DELAY = 5))))"
$username = "username"
$password = "password"
$queryStatment = "SELECT [PROG_TYPE] FROM NC_PROGRAMS FETCH FIRST 10 ROWS ONLY"
#Load Required Types and modules
Add-Type -Path $OracleDLLPath
Import-Module SqlServer
Write-Host $queryStatment
#Create the connection string
$connectionstring = 'User Id=' + $username + ';Password=' + $password + ';Data Source=' + $datasource
#Creates a data adapter for the command
$da = New-Object Oracle.ManagedDataAccess.Client.OracleDataAdapter($cmd);
#The Data adapter will fill this DataTable
$resultSet = New-Object System.Data.DataTable
#Only here the query is sent and executed in Oracle
[void]$da.fill($resultSet)
#Close the connection
$con.Close()
WRITE-HOST $resultSet
This gives an error though:
Add-Type : Unable to load one or more of the requested types. Retrieve
the LoaderExceptions property for more information.
I am new to programming in general. I would really appreciate if someone could provide detailed steps on resolving this. Thanks in advance.

TFS Query or SQL Query to Identify Empty Test Plans or Empty Test Suites

We are fairly new to TFS and I have been trying to clean up some of the areas. I can see through a simple TFS query that there are over 180 Test Suites with the name "New suite"... I don't want to try to open each one and look to see if there are test cases assigned to it.
Is there a way to get a report of Empty Test Suites, and maybe Empty Test Plans?
Thanks
Pat
You can use REST API to Get a list of test suites, "testCaseCount" will be included in the response. See below example:
GET https://fabrikam-fiber-inc.visualstudio.com/DefaultCollection/fabrikam-fiber-tfvc/_apis/test/plans/1/suites?api-version=1.0
For more information please refer to https://www.visualstudio.com/en-us/docs/integrate/api/test/suites
Besides, you can also get the empty Test Suites or Test Plans by running the sql query in SQL Server, see below sample.
SELECT
[SuiteId]
,[PlanId]
,[ParentSuiteId]
,[Title]
,[TestCaseCountFromMtm]
,[TestCaseCountFromWeb]
FROM [Tfs_CollectionLC].[dbo].[tbl_Suite]
WHERE [TestCaseCountFromMtm]='0' and [TestCaseCountFromWeb]='0'
Update:
If you want to get the Plan and Parent Suite name, in above query the "Title" column will display all the suite name including the Parent Suite name. I didn't find the exact table to get the Plan name, but we can get it via REST API, you can use below sample PowerShell script to get all the Test Plan names. Just copy/paste the script and save it as .ps1 file to run on your client.
$project = "TFVC-Scrum" # Change to your team project name here
$baseUrl = "http://12r2:8080/tfs/CollectionLC" # Change to your TFS Collection URL
$testplanUrl = "{0}/{1}/_apis/test/plans?api-version=1.0" -f $baseUrl, $project
$TestPlans = (Invoke-RestMethod -Uri $testplanUrl -Method Get -UseDefaultCredential).value
$TestPlanResults = #()
foreach($TestPlan in $TestPlans){
$testplanitemUrl = "{0}/{1}/_apis/test/plans/{2}?api-version=1.0&includeDetails=true" -f $baseUrl,$project, $TestPlan.id
$TestPlanItem = Invoke-RestMethod -Uri $testplanitemUrl -Method Get -UseDefaultCredential
$customObject = new-object PSObject -property #{
"TestPlanid"= $TestPlanItem.id
"TestPlanName"= $TestPlanItem.name
}
$TestPlanResults += $customObject
}
$TestPlanResults | Select `
TestPlanid,
TestPlanName

How to run an specific test case in the selected environment in SoapUI

I have multiple Environment and a lot of test cases, but not all test cases are needed to be run in all environment. Is there a way to run only an specific test cases from a test suite based on the selected Environment.
For Example
If I select Environment1, it will run the following test cases
TC0001
TC0002
TC0003
TC0004
TC0005
If I select Environment2, it will run only the following test cases
TC0001
TC0003
TC0005
There can be different solution to achieve this since you have multiple environments i.e., pro software being used.
I would achieve the solution using Test Suite's Setup Script:
Create Test Suite level custom property. Use the same name as your environment name. For instance, DEV is the environment defined, use the same as test suite property name and provide the list of values separated by comma as value for that property, say TC1, TC2 etc.,
Similarly defined other environments and its values as well.
Copy the below script in Setup Script for the test suite and execute the script which enables or disables the test cases according to the environment and property value
Test Suite's Setup Script
/**
* This is soapui's Setup Script
* which enables / disables required
* test cases based on the user list
* for that specific environment
**/
def disableTestCase(testCaze) {
testCaze.disabled = true
}
def enableTestCase(testCaze) {
testCaze.disabled = false
}
def getEnvironmentSpecificList(def testSuite) {
def currentEnv = testSuite.project.activeEnvironment.NAME
def enableList = testSuite.getPropertyValue(currentEnv).split(',').collect { it.trim()}
log.info "List of test for enable: ${enableList}"
enableList
}
def userList = getEnvironmentSpecificList(testSuite)
testSuite.testCaseList.each { kase ->
if (userList.contains(kase.name)) {
enableTestCase(kase)
} else {
disableTestCase(kase)
}
}
Other way to achieve this is using Event feature of ReadyAPI, you may use TestRunListener.beforeRun() and filter the test case whether to execute or ignore.
EDIT:
If you are using ReadyAPI, then you can the new feature called tag the test cases. A test case can be tagged with multiple values and you can execute tests using specific tags. In this case, you may not needed to have the setup script as that is for the open source edition. Refer documentation for more details.
This solution is only specific to Pro software and Open Source edition does have this tag feature.

How to automate MDX testing of SSAS

I've developed some MDX queries which are used to test our SSAS cube. I would like to automate these queries so that I could execute them all with a click of a button and ideally green bar/red bar based on their output.
Is there a way I could hook these queries up with Visual Studio to get this behavior?
You can try any unit testing framework here. Although unit tests aren't intended for such use, they can be useful there - test runners have red/green indicator out of the box.
Write test which executes mdx using ADOMD.NET ( http://j.mp/NtKFih ) and exception during execution will fail test. You can also investigate result using CellSet object and decide if test has passed.
Simple example using Microsoft's Unit Testing Framework (references To System.Data.dll and Microsoft.AnalysisServices.AdomdClient.dll are required):
using Microsoft.AnalysisServices.AdomdClient;
...
[TestMethod]
public void CubeHealthCheck1()
{
using (AdomdConnection conn = new AdomdConnection("Data Source=localhost;
Initial Catalog=SejmCube")) //your connection string here
{
conn.Open();
AdomdCommand cmd = conn.CreateCommand();
//your mdx here
cmd.CommandText = "SELECT NON EMPTY { [Measures].[Glosow Przeciwko] }
ON COLUMNS FROM [Sejm]";
CellSet cs = cmd.ExecuteCellSet();
}
}
Any exception will fail test (no connection for example) - you can add try/catch and in message inform what went wrong.
You can run this test from for example Test List Editor window
and then in Test Results window you have result with indicator
If you don't want using unit testing framework, you can develop custom visual studio extension (http://j.mp/QfMNQt) with similar logic inside.
You should check Nbi. This framework let you check the structure and members of your cubes but also compare query, mdx or sql, results to predefined or dynamic results. The documentation is relatively exhaustive for an open-source project.
Compared to other solutions, you don't need to code in C#, just an Xml file describing your tests is enough.

Creating BizTalk 2006 adapters programmatically

I'm writing a configuration script for a BizTalk server I need to create a few adapters.
In the "BizTalk Server Administration" application this is done by going to Biztalk Server Group / Platform Settings / Adapters and choosing New / Adapter from the right-click menu.
I'd like to automate this process somehow, using a Powershell script or a SQL script. I tried to use the adm_Adapter_Create stored procedure in teh Biztalk DB but it doesn't work all the way as no send / recieve handlers get configured.
Is there any way to automate this adapter creation?
You need to use WMI for this with the MSBTS_AdapterSetting class. There's some example code for this here.
Part of a Powershell script I wrote to solve this:
$adapterClass = [WMIClass] "root\MicrosoftBizTalkServer:MSBTS_AdapterSetting"
$adapter = $adapterclass.CreateInstance()
$adapter.Name = $adapterXml.name
$adapter.Comment = $adapterXml.comment
$adapter.Constraints = $adapterXml.constraints
$adapter.MgmtCLSID = $adapterXml.MgmtCLSID
$adapter.put() | Out-Null