VSCode + Unity's test framework? - c#

I installed VSCode for Unity game development a few weeks ago and have been using it as an alternative to my usual setup of VS + Resharper. I enjoy VSCode quite a bit, especially given how fast and lightweight it is.
One problem I have, however, is writing tests. It's standard practice at our studio to create unit tests for certain features we implement, and we so we have an assembly for running tests in a Unity project.
There's a testing .asmdef that references the NUnit framework DLL and the assembbly that has the code I want to test. In VS, if I navigate through the code, it all looks fine. If I switch to VSCode, however, it tells me there's compilation errors all over the place, because VSCode can't see any of the NUnit classes or the classes from the assembly I want to test (in Unity, I get 0 compilation errors even when writing new code).
Is there any VSCode setup I can do to get rid of the compilation errors and write tests normally, or do I have to switch to VS to write tests?

UPDATE: A work colleague helped me out and linked me this extension which clears up the compilation errors.
It looks like it lets me run tests from the IDE, too, but I haven't set it up yet as I just run them from Unity's Test Runner window. This isn't a priority for me, so I'll mark this as the answer.

Related

Resharper lost and cannot find my MSTestV2 unit tests

For years, I have generated my C# unit tests from the VS menu (MsTestV2) and used ReSharper to run the generated unit tests.
The problem is that from time to time (several times a year in my experience), ReSharper loses the unit tests and cannot find them or run them. No circles show up in my VS text editor gutter.
I have tried things such as cleaning the solution, rebuilding it, rebooting Vstudio, deleting my .suo file, clearing the ReSharper Options>General>Clear Caches, deleting/restoring the test project reference to the tested project, adding a new test case manually to the test class, adding a new test class, and probably a few other methods that I cannot remember. None of them helped.
I have a small note from a past instance that tells me to copy all my test files, delete the entire test project, recreate it, add a new dummy test case, and when ReSharper can see the new test in the new project, cut and paste and copy my old test files into the new project.
Naturally, the MsTest runner in Visual Studio finds and runs all my tests properly.
The current test project and test cases have been working properly for many months, and I would rather not rebuild the entire project again. The only recent new thing in the past day or two is an upgrade to VS 16.7.0 and upgrade to the latest ReSharper Ultimate 2020.1.4 built on 2020-07-02. That might be the issue because ReSharper can't find the MsTestV2 tests on other projects too. It would certainly be an easy combination to blame. But my question is really about a reliable procedure for getting ReSharper to find unit tests that it has lost.
Does anyone know of a reliable way to get Resharper to find the current test projects and test cases again?

Why doesn't building my UWP Unit Test project produce a test dll

I'm trying to run unit tests from the command line.
For this, I need the test dlls, as per this:
https://msdn.microsoft.com/en-us/library/ms182490.aspx
In the Prerequisites section on that page, it says I need to "Run a Unit Test and Fix Your Code"
Question 1: Do I need to run tests from VS to be able to run them from command line? Surely not?
Now to the more important bit. When I build my solution, regardless of whether it's via VS or command line using MSBuild, I do not get any dlls generated for my tests.
I know this is for C++ but thought might still be relevant https://social.msdn.microsoft.com/Forums/vstudio/en-US/a89c2173-90e6-47b2-af8e-48865969cbca/msbuild15-does-not-create-a-dll-file-after-building-the-c-native-unit-test-project?forum=msbuild. (not that it helped of course).
Question 2: Why don't my unit test dlls get generated when building?
UWP is a bit different from other projects when it comes to Unit Testing. Universal Windows Apps run in a sandbox to make sure they don't do things they don't have permissions for. For this reason, the unit test project is not a simple DLL only, but in fact a full-fledged UWP app (and the generated executable has appx extension), that is launched and performs the tests.
That said, you can still launch the unit test project from the console using a special command as you can see in this SO answer.
vstest.console.exe /Platform:x64 AppPackages\UnitTestProject1_1.0.0.0_x64_Debug_Test\UnitTestProject1_1.0.0.0_x64_Debug.appx

UWP project unit test: Inconclusive: A user callback threw an exception

I have a UWP project which fails to run unit tests via R#.
I know this was very cumbersome in the beginning of UWP, but I was able to get the unit tests going if I restarted Visual Studio a couple of times. A year later, and a major release further in VS2017 and R# I am still not able to run unit tests...
I'm using:
VS2017 Pro (15.4.3)
R# 2017.2.2 ultimate
UWP solution with target project Creators update (15063)
MS test project (15063)
When I open my solution, it doesn't matter which unit test I run, every test will be inconclusive.
Does anybody recognize these kind of issues and have a workaround for this? Any way to at least allow some kind of TDD way of working?
PS: Of course there isn't an actual stack-trace or inner exception in an output window which I can use for troubleshooting. It's just this pointless message without any useful suggestion how to move further

Unit tests failing in Jenkins

We have 10K+ unit tests in C# solution which are passed when running in local and in TFS.
Now, we are setting up Jenkins for our solution stack and we are facing issue of around 250 Unitests failing consistently.
The same unit tests are passed when i tried running them in jenkins setup server by using Visual Studio and Commnad prompt(MSTest).
What do you think is the issue? Any leads to look at this issue will be helpful.
Edit 1:
I did the research and not able to find anything as the problem itself is strange one. If you are not clear please raise questions instead of Down voting.
Edit 2:
I am able to find out the issue. It is with the unittests dll config file. When i executed MSTest in server by removing the config file, i am seeing same set of tests failing which are failing with Jenkins setup.
I guess we need to modify the steps configure in Jenkins portal to load the unittests dll config file.
My guess would be you have tests that are not actually Unit tests, but instead are integration tests or worse, and they fail non-deterministically. Other than that, you're asking people to do the impossible here without source code posted.
Either post source, or hire a consultant who knows about Jenkins IMO.
There might be issues with conditional compilation symbols (e.g. DEBUG vs. RELEASE code): in VS you normally run the tests on a DEBUG build, on the CI server on a release build.
Also look at some global state not being cleaned up correctly. Some threads which may still be running after a test has seemingly finished may corrupt later tests even when those later tests are located in a different test dll. That can sometimes be detected if test failure depends on the order of tests run.
Another issue often faced is dependency on test data in files: the files may be missing in the virtualized environment where the test is actually run. Use the Deployment attribute.
I had a similar problem with NCrunch. Maybe you can check in VS your "Build"-tag the Platform target. It should be the same like Jenkins is configured. For example "Platform target" is x64, it should be used in Jenkins as well.

Test discovery tool for .NET

Is there a tool for automated test discovery for .NET. I am using the Visual Studio unit testing stuff and wanted functionality similar to Python Nose. I need to have a tool automatically discover all the unit test available and run for example the ones "marked" as unit and in different scenarios run the tests "marked" as Integration and so on. I have found an individual that has created his own implementation of the MSBuild test task and an considering creating my own with annotation attributes to do what Nose does but wanted to see if anyone was aware of an existing tool that could work.
Thanks
Visual Studio integrated test framework does exactly that when running from the IDE.
If you need a command line tool that does exactly the same functionality (finds all the tests in a specific directory/solution) I guess you have to write something.
Because MSTest command line needs at least the assembly to be specified. I suggest you write a short script that iterates all the assemblies and find if they have tests in them and then run each assembly using MSTest.exe
Update:
I've just published a new CodePlex project called #Nose that does exactly what you need. Currently it only supports NUnit but I plan on adding VSTest as well.
Try ReSharper from JetBrains. It does what you want with unit tests plus a whole lot more.

Categories

Resources