This article describes setting the VS Code settings to point the debugging target at the build output of the unit test project. I have therefore set mine like this:
{
"explorer.confirmDragAndDrop": false,
"git.allowForcePush": true,
"git.autofetch": true,
"window.zoomLevel": 0,
"csharp.unitTestDebuggingOptions": {
"sourceFileMap": {
"C:\\git\\MsTester\\bin\\Debug\\netcoreapp2.1": "C:\\git\\MsTester\\bin\\Debug\\netcoreapp2.1"
}
},
"files.autoSave": "afterDelay",
"files.exclude": {
"**/bin": true,
"**/node_modules": true,
"**/obj": true
},
"csharpfixformat.style.spaces.insideEmptyBraces": false,
"csharpfixformat.style.braces.allowInlines": false,
"csharpfixformat.style.spaces.beforeParenthesis": false,
"csharpfixformat.style.spaces.afterParenthesis": false,
"csharp.format.enable": false,
"extensions.ignoreRecommendations": true
}
However, I am not sure how to setup the launch.json to kick off the dotnet test so that it can attach the debugger.
This is what I've got currently:
{
"version": "0.2.0",
"configurations": [
{
"name": "MsTester",
"type": "coreclr",
"request": "launch",
"preLaunchTask": "build",
"program": "${workspaceFolder}/MsTester/bin/Debug/netcoreapp2.1/MsTester.dll",
"windows": {
"args": [
"--filter",
"TestCategory=lbshell",
"--logger",
"trx",
"--results-directory",
".\\TestResults",
"--settings",
".\\Features\\runsettings.xml"
],
},
"cwd": "${workspaceFolder}/MsTester",
"console": "internalConsole",
"stopAtEntry": false,
"internalConsoleOptions": "openOnSessionStart"
},
]
}
Is there an option to tell VS Code that it needs to execute dotnet test instead of dotnet run?
I was hoping this page would indicate how to do that, but it does not.
All credit is due to #Lance U. Matthews as he posted this as a comment to an answer to the question: How does one debug an MSTest in VSCode? . I am reposting this as a proper answer because he hasn't done so in a year.
The following answer has been tested on VSCode v1.62.3 and dotnet tools v5.0.403.
Assuming you have a .NET solution with a structure like this:
mysolution.sln
tests\
|---> tests.csproj
|---> UnitTest1.cs
.vscode\
|---> launch.json
|---> tasks.json
Copy the following into the tasks.json file:
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"label": ".NET Core Test with debugger",
"type": "process",
"isBackground": true,
"command": "dotnet",
"args": [ "test" ],
"options":
{
"cwd": "${workspaceFolder}/tests",
"env":
{
"VSTEST_HOST_DEBUG": "1"
},
},
"group": "test", "presentation":
{
"echo": true,
"reveal": "always",
"focus": false,
"panel": "shared"
},
"problemMatcher": []
},
]
}
And this into the launch.json file:
{
"version": "0.2.0",
"configurations": [
{
"name": ".NET Core Attach",
"type": "coreclr",
"request": "attach"
}
]
}
Now set a breakpoint anywhere in your UnitTest1.cs file and run .NET Core Test with debugger task (Terminal->Run task...).
The Test Execution Command Line Tool should launch and at the bottom of your terminal should be something like:
Your Process Id will certainly be different but that is expected behavior.
Now you need to switch to "Run and Debug" tab (ctrl+shift+d) and select ".NET Core Attach" (it should be in the upper left part of the VSCode).
Provide the process id that appeared previously in the terminal:
Now click F5 once and you should reach one of your breakpoints.
This may not answer solve your problem of passing the arguments entirely, but may solve the problem of passing runsettings parameters to the code being debugged. Using this method, I was able to pass the contents of runsettings to my code when running the debugger (i.e. when I click "Debug Test" above the method):
What I ended up doing is this:
First, I wrote a bit of code that will read from the settings file (via TestContext) OR from the user environment if the key was not available in the settings file, i.e.:
[ClassInitialize]
public static void TestClassInitialize(TestContext context)
{
v = Settings.GetSettingValueFromContextOrEnvironment("v", context);
}
Here is the implementation of GetSettingValueFromContextOrEnvironment:
/// <summary>
/// Attempts to read a setting value from the context (populated through runsettings). If the
/// key is not present in the context, the value will be read from the user environment variable
/// instead.
///
/// This allows running the unit test code in VSCode debugger that currently doesn't seem to allow
/// passing runsettings file to the DLL.
/// </summary>
/// <param name="name"></param>
/// <param name="context"></param>
/// <returns></returns>
public static String GetSettingValueFromContextOrEnvironment(string name, TestContext context){
if (context.Properties.ContainsKey(name)){
return context.Properties[name].ToString();
} else {
String envVar = Environment.GetEnvironmentVariable(name, System.EnvironmentVariableTarget.User);
if (envVar == null){
throw new Exception(String.Format("Environment variable '{0}' was not available neither in the context file nor in the environment.", name));
} else {
return envVar;
}
}
}
I then wrote a Powershell that will read my settings file to parse parameters and set them as user environment variables, like this:
<# This script updates user environment variables with parameters stored in *.runsettings file that is provided to it as the only argument on the command line.
Example usage:
.\set_settings_env.ps1 local.runsettings
#>
param (
[Parameter(Mandatory=$true)][string]$settings_file
)
[xml]$xml = Get-Content $settings_file
foreach( $parameter in $xml.RunSettings.TestRunParameters.Parameter)
{
write-host("Setting environment variable: " + $parameter.name)
[Environment]::SetEnvironmentVariable($parameter.name, $parameter.value, "User")
}
So now I am able to both run the code from command line with a specific runsettings file and debug by running the script to set my environment variables.
Perhaps this is more what you are looking for:
How does one debug an MSTest in VSCode?
(also check the comment).
So by using "VSTEST_HOST_DEBUG": "1" you should be able to attach a debug process, similar to how one can do it in Java.
Related
Trying to update logic from checking fails within parallel flows in a AWS Step Function. The parallel flows have following logic to handle error:
"Subflow failed": {
"Type": "Pass",
"End": true,
"Result": true,
"ResultPath": "$.fail"
}
Once the parallel flows have finished the step function proceeds to check if any of the flows failed using the following logic:
"Any parallel flow fail?": {
"Type": "Choice",
"Choices": [
{
"Or": [
{
"And": [
{
"Variable": "$[0].fail",
"IsPresent": true
},
{
"Variable": "$[0].fail",
"BooleanEquals": true
}
]
},
This approach works but leads to an issue when developing new sub flows without adding a new block to check the fails in the array for new flow. I would like to find a more scalable method for checking the array if it contains the fail variable.
I have tried to use the States.ArrayContains but the usage and syntax is unfamiliar to me so I wasn't able to get valid syntax when trying to plug in into the check. Couldn't find any concrete examples of using the method online so any help is much appreciated.
I would like to create a human review loop for images that undergone OCR using Amazon Textract and Entity Extraction using Amazon Comprehend.
My process is:
send image to Textract to extract the text
send text to Comprehend to extract entities
find the Block IDs in Textract's output of the entities extracted by Comprehend
add new Blocks of type KEY_VALUE_SET to textract's JSON output per the docs
create a Human Task with crowd-textract-analyze-document element in the template and feed it the modified textract output
What fails to work in this process is step 5. My custom entities are not rendered properly. By "fails to work" I mean that the entities are not highlighted on the image when I click them on the sidebar. There is no error in the browser's console.
Has anyone tried such a thing?
Sorry for not including examples. I will remove secrets/PII from my files and attach them to the question
I used the AWS documentation of the a2i-crowd-textract-detection human task element to generate the value of the initialValue attribute. It appears the doc for that attribute is incorrect. While the the doc shows that the value should be in the same format as the output of Textract, namely:
[
{
"BlockType": "KEY_VALUE_SET",
"Confidence": 38.43309020996094,
"Geometry": { ... }
"Id": "8c97b240-0969-4678-834a-646c95da9cf4",
"Relationships": [
{ "Type": "CHILD", "Ids": [...]},
{ "Type": "VALUE", "Ids": [...]}
],
"EntityTypes": ["KEY"],
"Text": "Foo bar"
},
]
the a2i-crowd-textract-detection expects the input to have lowerCamelCase attribute names (rather than UpperCamelCase). For example:
[
{
"blockType": "KEY_VALUE_SET",
"confidence": 38.43309020996094,
"geometry": { ... }
"id": "8c97b240-0969-4678-834a-646c95da9cf4",
"relationships": [
{ "Type": "CHILD", "ids": [...]},
{ "Type": "VALUE", "ids": [...]}
],
"entityTypes": ["KEY"],
"text": "Foo bar"
},
]
I opened a support case about this documentation error to AWS.
The below step function is executed in aws and when there is a missing of a required parameter it cancel the flow and throws States.Runtime Error. This is in catch phase of the step function but it is not catching the error as stated.
Defined Step function is as below,
{
"StartAt": "Log Start Step Function",
"Comment": "Executed with inputs",
"States": {
"Log Start Step Function": {
"Type": "Task",
"Resource": "arn:aws:lambda:eu-west-1:0000000:function:update",
"Parameters": {
"body": {
"itemID.$": "$.itemID",
"functionName.$": "$.stepFunctionName ",
"executionARN.$": "$$.Execution.Id",
"complete": false,
"inprogress": true,
"error": false
}
},
"Catch": [
{
"ErrorEquals": [
"States.Runtime"
],
"ResultPath": "$.taskresult",
"Next": "Log Failed Module"
},
{
"ErrorEquals": [
"States.ALL"
],
"ResultPath": "$.taskresult",
"Next": "Log Failed Module"
}
],
"ResultPath": "$.taskresult",
"Next": "Evaluate Module PA1"
}
}
}
Below is the step function,
And the error thrown is as below,
Runtime error is not executing Log failed module.
{
"ErrorEquals": [
"States.Runtime"
],
"ResultPath": "$.taskresult",
"Next": "Log Failed Module"
},
Is this AWS error or something wrong with the configuration which is done here or is there any other way to validate parameters in AWS Step Functions
From https://docs.aws.amazon.com/step-functions/latest/dg/concepts-error-handling.html
A States.Runtime error is not retriable, and will always cause the execution to fail. A retry or catch on States.ALL will not catch States.Runtime errors.
Your state machine is expecting the following as input:
"Parameters": {
"body": {
"itemID.$": "$.itemID",
"functionName.$": "$.stepFunctionName ",
"executionARN.$": "$$.Execution.Id",
"complete": false,
"inprogress": true,
"error": false
}
},
You need to pass them when you start a new execution instead of:
{
"Comment": "Insert your JSON here"
}
Which you are currently passing because it comes by default as the input body of a new execution in the AWS Console.
Read more about InputPath and Parameters here: https://docs.aws.amazon.com/step-functions/latest/dg/input-output-inputpath-params.html
I have the same problem.
I am beginning to think that the runtime error happens when the input path is processed, and before the catcher can be initialized. This means that try / catch to test for parameters present in the input is not possible. I also tried ChoiceState, to no avail.
So I think there is no solution but to provide every parameter you refer to in the state machine definition. But the documentation is not clear on this.
This caught me out too. My scenario was setting the output based on the results of S3 ListObjectVersions, with the versions to be deleted in a later task. In this case, $.Versions didn't exist because there was nothing in the bucket so States.Runtime was thrown.
{
"bucket.$": "$.Name",
"objects.$": "$.Versions"
}
To work around this -
I don't transform the result of ListObjectVersions task with ResultSelector. Instead this state simply outputs the unedited result.
I added a Choice state underneath with a rule to check if $.Versions is present.
If it is present, move to a Pass state and transform the input in the exact same was a I was originally transforming the result of the ListObjectVersions task using the ResultSelector (because the Pass state doesn't transform on output, only input).
If it is not present, move to a Success state because there is nothing to delete.
Here is a screen grab of the relevant section, just in case it's helpful to visualise.
I have a lambda function that executes successfully with an intent called GetEvent that returns a specific string. I've created one utterance for this intent for testing purposes (one that is simple and doesn't require any of the optional slots for invoking the skill), but when using the service simulator to test the lambda function with this utterance for GetEvent I'm met with a lambda response that says "The response is invalid". Here is what the interaction model looks like:
#Intent Schema
{
"intents": [
{
"intent": "GetVessel",
"slots": [
{
"name": "boat",
"type": "LIST_OF_VESSELS"
},
{
"name": "location",
"type": "LIST_OF_LOCATIONS"
},
{
"name": "date",
"type": "AMAZON.DATE"
},
{
"name": "event",
"type": "LIST_OF_EVENTS"
}
]
},
{
"intent": "GetLocation",
"slots": [
{
"name": "event",
"type": "LIST_OF_EVENTS"
},
{
"name": "date",
"type": "AMAZON.DATE"
},
{
"name": "boat",
"type": "LIST_OF_VESSELS"
},
{
"name": "location",
"type": "LIST_OF_LOCATIONS"
}
]
},
{
"intent": "GetEvent",
"slots": [
{
"name": "event",
"type": "LIST_OF_EVENTS"
},
{
"name": "location",
"type": "LIST_OF_LOCATIONS"
}
]
}
]
}
With the appropriate custom skill type syntax and,
#First test Utterances
GetVessel what are the properties of {boat}
GetLocation where did {event} occur
GetEvent get me my query
When giving Alexa the utterance get me my query the lambda response should output the string as it did in the execution. I'm not sure why this isn't the case; this is my first project with the Alexa Skills Kit, so I am pretty new. Is there something I'm not understanding with how the lambda function, the intent schema and the utterances are all pieced together?
UPDATE: Thanks to some help from AWSSupport, I've narrowed the issue down to the area in the json request where new session is flagged as true. For the utterance to work this must be set to false (this works when inputting the json request manually, and this is also the case during the lambda execution). Why is this the case? Does Alexa really care about whether or not it is a new session during invocation? I've cross-posted this to the Amazon Developer Forums as well a couple of days ago, but have yet to get a response from someone.
This may or may not have changed -- the last time I used the service simulator (about two weeks ago at the time of writing) it had a pretty severe bug which would lead to requests being mapped to your first / wrong intent, regardless of actual simulated speech input.
So even if you typed in something random like wafaaefgae it simply tries to map that to the first intent you have defined, providing no slots to said intent which may lead to unexpected results.
Your issue could very well be related to this, triggering the same unexpected / buggy behavior because you aren't using any slots in your sample utterance
Before spending more time debugging this, I'd recommend trying the Intent using an actual echo or alternatively https://echosim.io/ -- interaction via actual speech works as expected, unlike the 'simulator'
For example I want to require:
{
"repositories": [
{
"type": "git",
"url": "https://github.com/google/google-api-php-client.git"
}
],
"require": {
"google/apiclient": "v1-master"
}
}
In this example I try require google/apiclient on branch v1-master. I get error:
[UnexpectedValueException]
Could not parse version constraint v1-master: Invalid version string "v1-master"
You need to prefix all dev branches (= non tagged) by dev-.
To install the branch you need, use:
composer require google/apiclient:dev-v1-master
See composer docs.
this will work :
{
"repositories": [
{
"type": "git",
"url": "https://github.com/google/google-api-php-client.git"
}
],
"require": {
"google/apiclient": "dev-BRANCH_NAME"
}
}
so pattern is "dev-*", if you branch name is "bug-fix" then "dev-bug-fix"
with command line :
composer require google/apiclient:dev-BRANCH_NAME
I was trying to the same for a different Google repository which contains several packages and it took me some time to figure it out. Therefore I am sharing my solution below.
My goal is to pull latest google/cloud-compute from https://github.com/googleapis/google-cloud-php.git within master branch.
Following steps worked for me:
Clone the repository
git clone https://github.com/googleapis/google-cloud-php.git google-cloud-php
Set composer.json to use the right package from local folder:
{
"repositories": [
{
"type": "path",
"url": "/Users/USERNAME/projects/google-cloud-php/Compute"
}
],
"require": {
"google/cloud-compute": "dev-master"
}
}
Please note that in step 2 the url is pointing to the Compute subfolder where the actual google/cloud-compute package exists.
My solution could be easily tweaked for any branch, you would just need to git checkout the appropriate branch in step 1 and then change 'dev-master' to 'dev-YOUR_BRANCH' in step 2.