0

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?

Ash
  • 2,021
  • 2
  • 26
  • 59
  • I thought I'd be used to this by now but it still continues to amaze me how .Net development is more of a constant battle of getting SDKs, packages, compilers, IDE, frameworks, dlls, and a plethora of other things working well together than it is about simply coding. If it wasn't for this beautiful language called C# (and it really is the only little thread Microsoft are hanging by imo), I'd probably would've ended up being a dentist (much easier problems to drill into). – Ash Mar 21 '18 at 05:28
  • I understand, but still much better than the JavaScript's new-framework-a-day world :-D . – Martin Zikmund Mar 21 '18 at 06:23

1 Answers1

2

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
Martin Zikmund
  • 38,440
  • 7
  • 70
  • 91
  • 1
    I see. Well the good thing is I do get a .appx generated upon build, so will try to run this from command line using vstest.console.exe (once I fix cert issues) and get back to you. – Ash Mar 21 '18 at 06:36
  • Not a requirement for this question but still a bit relevant: https://stackoverflow.com/questions/49442040/can-vstest-console-exe-run-an-appx-without-a-security-certificate – Ash Mar 23 '18 at 03:50