Given a TFS build detail (IBuildDetail) with .Status of PartialSuccess, and .TestStatus of Failed how might I go about retrieving the list of tests (MSTest) that have failed on that build?
I have a working sandbox in which I can contact TFS via the SDK and retrieve the latest PartialSuccess build, but can't seem to find which service might have this unit test data and how I might go about querying it.
Can anyone shed some light?
This article is a great resource, actually it was the only one I had found available when I was searching something similar.In general you need access to ITestManagementService.Given you already have connection to a teamProjectCollection and a buildDetail, something like this should work out for you :
var tstService = (ITestManagementService)teamProjectCollection.GetService(typeof(ITestManagementService));
ITestManagementTeamProject testManagementTeamProject = tstService.GetTeamProject(buildDetail.TeamProject);
IEnumerable<ITestRun> testRuns = testManagementTeamProject.TestRuns.ByBuild(buildDetail.Uri);
foreach (var testRun in testRuns)
{
ITestCaseResultCollection testcases = testRun.QueryResultsByOutcome(TestOutcome.Failed);
foreach (var testcase in testcases)
{
Console.WriteLine("TestCase ID: " + testcase.TestCaseId);
Console.WriteLine("TestCase Title: " + testcase.TestCaseTitle);
Console.WriteLine("Error Message: " + testcase.ErrorMessage);
}
}
(This code is basically a copy from the article above, it is work by Anuj Chaudhary)
Remember to add "Microsoft.TeamFoundation.TestManagement.Client" in your ref list.
Related
I am using HERE-Android-SDK to build a simple navigation solution with offline maps.
While using the offline mode for the search addresses and calculation of a route, I can see that there are results returned from the address-search, which are not included in the installed offline map datasets. Is there anything additional which I need to do, in order to get only search results which are located inside the offline-map data installed on my device?
I am using the following code snippets.
download offline maps for a specific country:
mapsLoader.selectDataGroup(MapPackage.SelectableDataGroup.TruckAttributes)
mapsLoader.installMapPackages(listOf(mapPackageId))
search request for addresses:
val term = "New York"
val center = GeoCoordinate(lastWayPoint.latitude, lastWayPoint.longitude)
val request = SearchRequest(term)
request.connectivity = Request.Connectivity.OFFLINE
request.locale = Locale.GERMAN
request.setSearchCenter(center)
request.collectionSize = 5
request.execute { data, error ->
if (error != ErrorCode.NONE) return
// handle search results here
}
Thanks for all of your help in advance!
I have a vNext build which runs a few NUnit tests and publishes the results. However, the output produced by the tests is not published, even though it is found in the respective XML file.
For example:
But, if I inspect the respective XML files - it is there:
Notice the <output> element.
I would very much like to see this output published along the test results. How can I do it?
P.S.
There is another problem with the publishing. The Run Duration is reported as 4h 59m in the top pane, but in the bottom details pane it is the correct 10:48.176 minutes. The 4h 59m looks very much as 5h, which is the time difference between EST and UTC. The tests were run on an Octopus server and were fetched by the vNext build. Maybe there is a time zone confusion somewhere.
EDIT 1
We have an on-premises TFS
EDIT 2
Examining the source code of the Publish Test Results task reveals that it uses Microsoft.TeamFoundation.TestClient.PublishTestResults assembly to parse the NUnit XML test result. Specifically the following C# code is used to parse the test-case element (NUnit3ResultsXmlReader.cs):
if (testCaseResultNode.Attributes["result"] != null)
{
testCaseResultData.TestCaseResult.Outcome = !string.Equals(testCaseResultNode.Attributes["result"].Value, "Passed", StringComparison.OrdinalIgnoreCase) ? (!string.Equals(testCaseResultNode.Attributes["result"].Value, "Failed", StringComparison.OrdinalIgnoreCase) ? (!string.Equals(testCaseResultNode.Attributes["result"].Value, "Skipped", StringComparison.OrdinalIgnoreCase) ? TestOutcome.Inconclusive.ToString() : TestOutcome.NotExecuted.ToString()) : TestOutcome.Failed.ToString()) : TestOutcome.Passed.ToString();
XmlNode xmlNode1 = testCaseResultNode.SelectSingleNode("failure");
if (xmlNode1 != null)
{
XmlNode xmlNode2 = xmlNode1.SelectSingleNode("message");
XmlNode xmlNode3 = xmlNode1.SelectSingleNode("stack-trace");
testCaseResultData.TestCaseResult.ErrorMessage = xmlNode2 != null ? xmlNode2.InnerText : (string) null;
testCaseResultData.TestCaseResult.StackTrace = xmlNode3 != null ? xmlNode3.InnerText : (string) null;
XmlNode xmlNode4 = testCaseResultNode.SelectSingleNode("output");
if (!string.IsNullOrWhiteSpace(xmlNode4 != null ? xmlNode4.InnerText : (string) null))
testCaseResultData.ConsoleLog = xmlNode4.InnerText;
}
}
From which it follows that the assembly authors think that test output is only useful when the test-case in question has failed. This is an unfortunate decision, because it is not up to them to decide when the output is useful. If it is in the test results XML, then it should be published.
Opened a new issue https://github.com/Microsoft/azure-pipelines-tasks/issues/8979
Opened an Azure DevOps feature request - https://developercommunity.visualstudio.com/idea/432166/the-publish-tests-azure-devops-plugin-should-publi.html
My solution to this unfortunate behavior force upon us is to mangle the XML test result before handing it off to the Publish Test Results task.
The following powershell code does the trick:
$Modified = $false
$xml = [xml](cat $OriginalTestResultsXmlFile -Raw)
$xml.SelectNodes('//test-case') |? { !$_.failure -and $_.output } |% {
$Modified = $true
$_.InnerXml = #"
<!-- Workaround the issue https://github.com/Microsoft/azure-pipelines-tasks/issues/8979. No real failure here -->
<failure/>
$($_.InnerXml)
"#
}
if ($Modified)
{
$xml.Save($TestResultsXmlFile)
}
else
{
move $OriginalTestResultsXmlFile $TestResultsXmlFile
$OriginalTestResultsXmlFile = $TestResultsXmlFile
}
We have to trick the task into executing the logic we need by creating a dummy failure element besides the output element.
Lo and behold:
I have this table (m.Table) in my ui5 application that I'm sorting using the following example.
https://sapui5.hana.ondemand.com/1.42.7/explored.html#/sample/sap.m.sample.TableViewSettingsDialog/preview
I have a set of unit test (QUnit) where I test this functionality but I keep getting an error saying that "Object doesn't support method sort".
This is a snippet of my code
var oBinding = controls.searchResultsTable.getBinding("items");
var aSorter = [];
var sPath = "columnName";
aSorter.push(new Sorter(sPath, false));//sort in descending order
oBinding.sort(aSorter);
This code above takes care of the sorting when the application runs and everything works fine.
Here is a snippet of my testing
QUnit.test("valid search input", function(assert){
....
//my attempt at testing this
var getBinding = sinon.stub().returns(new sap.ui.model.Binding(),
function(){});
}
var oBinding = {getBinding: getBinding};
....
The error points to the line where I do aBinding.sort(aSorter);
Looking at the api, the sap.ui.model.Binding doesn't have any "sort()" functions. So I'm not sure how the sorting even works, let alone test it. Could someone give me some guidance here?
because sort is done on sap.ui.model.ListBinding as you are doing a binding on table items. Link
Also there are different other Bindings which extends sap.ui.model.Binding like sap.ui.model.PropertyBinding(binding on single UI control), sap.ui.model.TreeBinding(binding on Tree control) and so on.
Thank you for your help-
I'd like to know if my app successfully adds a document to the database using a unit test in Meteor. I'm using practicalmeteor:mocha and chai. The issue I'm running into is that I don't know how to mock a this.userId, it keeps telling me I'm not logged in.
it('inserts the draft agenda document into the collection', function() {
// TODO: mock document to insert into collection
// TODO: mock userId and Agenda.insert
this.userId = "Not an empty string";
console.log("before spec, changing this.userId: " + this.userId) //is "Not an empty string"
Meteor.call('createAgenda', mockAgenda, function(res) {
console.log("callback with response: " + res); //You're not logged-in. [not-logged-in]
console.log("this.userId: " + this.userId) //is undefined
}
}
see https://docs.meteor.com/api/methods.html#DDPCommon-MethodInvocation-userId for more info on user id
test runner fails to import files in client directory
MochaRunner.runServerTests: failures: 1 when meteor methods are called
I have to call the server side meteor methods that have been declared in the testing context as if I am on the client, but I can't import the client files or operate as if I'm a client
MochaRunner.runServerTests: Starting server side tests with run id R7ocZh3Qva3rExTL9 runs basically every time
This seems useful but hasn't worked for me yet https://forums.meteor.com/t/testing-methods-which-use-this-userid/2292/8
Thank you for your help, any code examples would be great.
Remarks
I wanted to post a comment but do not have enough reputation. So here are some remarks. Since you are testing on the server, you can call a Meteor method without a callback. This will result in a synchronous execution and simplify your test. Otherwise you will have to let the test know it is finished by calling the done function in your callback, see mocha docs.
Using mdg:validated-method
You can call a valited method and provide the context in which they execute using the _execute function. Below is an example taken from the todos sample project. For more examples you can take a look at their Lists and Todos tests.
it('makes a list private and updates the todos', function() {
// Check initial state is public
assert.isFalse(Lists.findOne(listId).isPrivate());
// Set up method arguments and context
const methodInvocation = {
userId
};
const args = {
listId
};
// Making the list private adds userId to the todo
makePrivate._execute(methodInvocation, args);
assertListAndTodoArePrivate();
// Making the list public removes it
makePublic._execute(methodInvocation, args);
assert.isUndefined(Todos.findOne(todoId).userId);
assert.isTrue(Todos.findOne(todoId).editableBy(userId));
});
Using standard methods
Another possiblity would be to bind the standard call function to the correct context. Note that this is just a thought and not tested.
var methodInvocation = {
userId: "some user id"
};
Meteor.call.bind(methodInvocation)('createAgenda', mockAgenda);
I am trying to learn how to use jsPlumb in my Ember.js application so I put a minimal jsFiddle together to demonstrate how they could work together.
In this example so far I just insert the nodes and add them to jsPlumb. I have not added any links between them yet. At this stage the nodes should be draggable but they are not.
Error I get in the browser console:
TypeError: myOffset is null
Which points to this part of the code in jsPlumb:
for (var i = 0; i < inputs.length; i++) {
var _el = _getElementObject(inputs[i]), id = _getId(_el);
p.source = _el;
_updateOffset({ elId : id });
var e = _newEndpoint(p);
_addToList(endpointsByElement, id, e);
var myOffset = offsets[id], myWH = sizes[id];
var anchorLoc = e.anchor.compute( { xy : [ myOffset.left, myOffset.top ], wh : myWH, element : e });
e.paint({ anchorLoc : anchorLoc });
results.push(e);
}
You can see that a simple example without integration with Ember.js works as expected. I know that this version of jsPlumb I have uses jquery-ui to clone elements and support drag and drop. A post here shows there is an issue with jquery-ui draggable functionality in Ember. However, I am not sure if I am hitting the same problem. If that is the same issue I am having, I would appreciate some help in how to implement the solution suggested there in my application. I am new to both Ember and jsPlumb, so I would appreciate clear guidance about what is going on here and what path to take.
How can I make this example work?
Luckily my suspicion was wrong and the issue was not with metamorph. jsPlumb and Ember work just fine together, without any hacks. I put a little example in this jsFiddle that demonstrates how they could work together.
Credit goes to Simon Porritt who helped me at jsPlumb user group to identify the problem. What I was missing was a simple call to jsPlumb.draggable element. However, the above error persisted after this fix.
The particular error message above was result of Ember calling didInsertElement an extra time with an element which did not make it to the DOM. I have reported this issue. One workaround is to check the element makes it into the DOM before calling jsPlumb. As you can see in the jsFiddle I have added this code in the didInsertElement hook to get rid of the error.
elementId = this.get 'elementId'
element = $("#"+elementId)
if element.size() > 0
console.log "added element", element
jsPlumb.addEndpoint element, endpoint
jsPlumb.draggable element
else
console.log "bad element"
Hope this helps someone.