vscode.executeDefinitionProvider returns empty vscode.Location[] when tests are called via package manager - visual-studio-code

I'm creating my first VS Code extension, but now I stuck while testing my extension automatically.
If I run my automated tests out of VS Code everything works fine, but I want to run the tests also in a continuous integration pipeline which is why the tests should also run if I call them with npm run test.
With npm run test most of my tests run successful, but as far as a test-method depends on the "vscode.executeDefinitionProvider"-output the tests fail, because it does not find any definitions.
await vscode.commands.executeCommand<vscode.Location[]>('vscode.executeDefinitionProvider', document.uri, positionToSearchForSymbols)
.then(definitions => {
if(definitions.length > 0){
//this one is called if I run the tests out of Visual Studio Code
} else{
//this one is called if I run the tests via npm rum test
}
});
Do you have any idea what I'm doing wrong? Why does npm run test behave different than running the tests out of VS Code?
Thanks in advance for your help.
David

Well, I got informed that VS Code sends a message to the language provider (in my case the al language extension) and that the issue has to be on the site of the language provider. Because the issue is not related to VS Code, I will close this question.

You need to setup your test environment to use specific extensions: How do I run integration tests for a vscode extension that depends on other extensions
You need to make sure that the extensions (in your case: DefinitionProvider) are activated before your tests start:
VSCode extension testing: Use `vscode.executeDefinitionProvider` in test
You might run into a situation where nothing of the above works for you. In that case this might help:
https://stackoverflow.com/a/69400358/6702598

Related

VS Code Extension tests not found on Azure Pipeline

I have an extension, initially created using the standard yo code template, and successfully uploaded to the market place. I have created a test suite, which works correctly when running locally (i.e. pressing F5), and I now wanted to add CI testing to the Github repo.
I followed the instructions on Continuous Integration and created a config file. The extension now builds successfully, however it appears that no tests are discovered.
For example, in this build I intentionally introduced a failing test, but it still passes.
Is there a step I'm missing or a good way to debug the problem?
See the Issue I opened for the answer. Currently, the tests fail silently if you do not have the required dependencies listed.

NUnit 3.2: Autorun tests after compile (Windows)

On a new VS solution, I've started using NUnit 3.2. Older versions (2.6) had a external NUnit GUI, that made it possible to watch assemblies and automatically run tests on modifications. But I cannot find anything similar to this for 3.2 - neither in the docs nor through Google.
I've installed NUnit.3.2.0.msi, I've also installed the NUnit3 Test Adapter in VS + NUnit3.2 nuget package for my project.
I can easily run all my tests through VS' Test Explorer. But I miss some way to run them automatically. Anyone know how?
In older versions of Visual Studio, there used to be an option to run tests after every build, but it was removed. It was always buggy and tended to lock files and prevent you from rebuilding.
You could set a post build command on your test project to automatically run NUnit console whenever your test project recompiles. You have NUnit console installed, so you could point to that, or use the NUnit.Runners package to install it into the packages folder of your solution.
Open your test project settings and go to the Build Events tab. Click on Edit Post-Build. Enter the following;
"C:\Program Files (x86)\NUnit.org\nunit-console\nunit3-console.exe" "$(TargetPath)"
Now, whenever you build, your tests will be run and the results will appear in the output window.
Maybe not ideal if there is a lot of build output after your tests but it works.
FYI, the colour in the build output is a side-effect of the VSColorOutput Visual Studio extension, it is not from NUnit.
Visual Studio captures STDOUT, so I haven't been able to get it to open a CMD window and run the tests. If anyone knows how to do that, add a comment and I will update.
There is a GUI for NUnit 3 under developement on GitHub - but it's not advised for production use yet.
We set our tests up using the NUnitLite runner. This allows you to turn your test assembly into an executable - and on run, will launch the console and run all tests. [Documentation]

Attach Current Build to Test

I'm playing around with Microsoft Test Manager 2013 (though it appears it is just MTM2012) to try and get a better understanding of test cases and test suites as I want to use this at work. So I was hoping that I could run a test suite on a build which gets included in this test suite. That is what I WANT to do, but it could very well be wrong. So maybe a better scope of what I'm doing at work might lend to a better answer.
My company makes tablet PC's. I write programs for those tablets. For sake of argument lets just say there are 5 tablets, that run a similar array of OS's. Tablet1,2,3 and 4 can run WinXP, WinXP embedded, Win7, and Win7 Embeded, and Tablet5 can run Win7, Win7 Embedded, and Win8 embedded. Lets say i'm making a Display test program. Naturally this display test will run differently on each tablet, but the program it self is supposed to be able to handle that along with not being able to worry about OS. So I wrote out a very simple test. Open Program, try to open again, verify only 1 instance, check display, close program.
I figured it would be good to make a Test Suite called "Complete Display Program Test" and put 5 sub test suites to that for each tablet. Then moved the 5 test cases to a single test suite. I configured all test cases to only have the correct tablet/OS configuration. Queued a build and waited for it to finish. I then attached that build to the main test suite. I then clicked on run a test for tablet 1 but I didn't see the build attached to the test runner. I've looked around a little bit to see why or how and haven't found anything. Question is is how do I do that? Or if you are scratching your head and wondering why in the world I am doing it this way then by all means suggest another way. This is the second time I have ever looked into MTM so I might not be doing it right.
Thank you for your time.
When running manual tests from MTM you will not see the build you are using in Test Runner.
But if you complete the test and set the test outcome you will be able to check which build you've ran the test against.
Just double-click on the test or select "View Results" to display test results:
This column is not visible by default. You will have to right-click on the column row and select the column "Buld number" to be displayed.
You will also be able to see the build number in "Analyse Test Runs" area:
The things are slightly different if you are running automated test.
Consider following approach:
Automate your Test Cases
See How to: Associate an Automated Test with a Test Case for details.
Create a Build Definition building your application under test AND assemblies containing your tests.
I strongly recommend build application you want to test and test assemblies using in the same Build Definition. (You will see why a little bit later).
Run this build definition and deploy the latest version of the application to the environment where you want run the tests.
This is very important to understand: if you run automated tests the tests assemblies only would be deployed automatically to the environment.
It's your job to deploy the right version of the application you are going to test.
Now you can run tests from MTM.
You can do it the way described by #AndrewClear in the comment to this answer: "choose "Run with Options" when you're beginning a test run" and select the latest build.
Now test assemblies containing tests which are using to automate Test Cases will be deployed automatically to the test environment and the tests will be executed.
That is the point you should recognize why is it so important to build application and tests with a single Build Definition: since the build number you've just selected when starting the tests will be stored along with the test results on TFS you will later know what version of you application you were testing (assuming you deployed the right version, of course).
You could go a little bit further if you want even more automation (This is the way I'm currently running automated tests)
Use Deploy-Build-Test template (this is a good place to start reading about Setting Up Automated Build-Deploy-Test Workflows).
Using this approach you will be able to automate deployment of the application you want to test.

How to Integrate NUnit With VS 2008

Hi i created a unit test case using NUnit.When i run the test NUnit it works fine.But i need to run it by using Visual studio.So i referred the NUnit website and followed the below steps
1)Right clicked the test project and clicked properties |Chose Debug option
2)checked the external program option and choosed the nUnit exe file.
3)And i run the test
Error i got:
Cannot start because the test project does not contain any test method.But i included 4 test methods which works in NUnit GUI.
Thanks in advance
Check out TestDriven.NET, a free Visual Studio add-in that allows you to run your unit tests with NUnit directly from the IDE.
Also ReSharper beautifully supports testing with NUnit!
http://www.jetbrains.com/resharper/features/unit_testing.html
On the Debug options tab, make sure to also set a command line argument with the name of your test assembly.

moq/Nunit - No tests are loaded or are disabled

When I try to run the tests, I get a message saying that the tests are not loaded or are disabled. I cannot see how to enable or activate the test code that has been created.
This seems to be a common error when installing/using addon Nunit or Moq but I have yet to find a link that has a solution.
If you know how to solve this problem please let us all know :) Thanks.
Visual Studio 2008 SP1 3.5SP1 .net
The Microsoft tests run ok.
This may sound stupid, but it's tripped me up more than once, are your test classes 1. Public and 2. Decorated with the [TestFixture()] attribute?
Also, your tests have the [Test] attribute, correct?
if you want to use Visual Studio Test Runner, you need to install the NUnit Test Adapter:
http://nunit.org/index.php?p=vsTestAdapter&r=2.6