Microsoft Native Unit Test for C++ - where is the Logger output going? - c++

Trying out C++ unit testing in Visual Studio 2019. Have added a C++ Native Unit Test Project unit test project to my solution. Then added the following Logger messages:
TEST_CLASS_INITIALIZE(ClassInitialize)
{
Logger::WriteMessage("Setup on test class. Where will this appear?");
}
// ...
TEST_METHOD(TestMethod1)
{
Logger::WriteMessage("Test method. Where is this message going??");
}
The tests are picked up by the Visual Studio Test Explorer and run successfully. Breakpoints are also hit if the tests are debugged. According to the Microsoft documentation on Logger, output should appear in the Visual Studio Output Window, but the messages are not being displayed.
Where is Logger sending its' output?

Although the MS documentation states "The logger class contains static methods to write to the Output Window" this no longer seems to be the case.
The output from the Logger Class can now be seen in the Test Detail Summary, after the unit tests have been run.
Output from the Logger::WriteMessage that is contained in TEST_METHOD(TestMethod1) will appear in the Test Detail Summary for that given unit test.
Output from the Logger::WriteMessage that is contained in TEST_CLASS_INITIALIZE(ClassInitialize) will appear in the first test method that is executed during that test run.

Related

Defining the order in which tests are displayed and run in Visual Studio

Using Visual Studio 2019 and trying out the MSTest, NUnit and xUnit testing frameworks with C#.
Say I have two methods:
// MSTest
[TestClass]
public class MyTests_MSTest
{
[TestMethod]
public void WantedToRunThisFirst()
{
// Arrange, Act, Assert...
}
[TestMethod]
public void ButThisRunsFirst()
{
// Arrange, Act, Assert...
}
}
Have tried the equivalent tests and syntax in all test frameworks (i.e. MSTest, NUnit and xUnit). Tests are always displayed in the Visual Studio Test Explorer section in alphabetical order (i.e. with ButThisRunsFirst at the top). And when the tests are run, the alphabetic order is used again and ButThisRunsFirst runs before WantedToRunThisFirst.
Tests should be independent so the run order shouldn't really matter, but having the tests listed and run to match the order in the code would be nice.
Is it possible to configure the display and/or run order of unit test methods?

Which unit test is currently running?

This question is related to the problem where my unit test procedure is crashing but I don't know on which unit test.
I realise this question is a duplicate of How can I find out which test method in a batch of test methods fails to run? but I need to try anyway:
I'm running some unit tests (about 118 of them), but one of them seems to make the Visual Studio unit test environment crash. This is what I see in the "output" window's "Tests" tab:
[5/02/2018 11:13:18 Informational] ------ Run test started ------
[5/02/2018 11:13:38 Error] The active Test Run was aborted because the execution process exited unexpectedly. The test execution process crashed while running the tests. To investigate further, open file:///C:/Users/DominiqueDS/AppData/Local/CrashDumps/vstest.executionengine.x86.exe.19136.dmp file in Visual Studio and choose "Debug in mixed mode".
[5/02/2018 11:13:38 Informational] ========== Run test finished: 65 run (0:00:19,6926824) ==========
The reason that I have that dump file is thanks to my Windows configuration which automatically creates such dumpfiles in case of a crashing application. (The procedure for this configuration is found under this URL)
Examining the dump file gives me more information on the test, which is failing: I have a hunch where I can find it, and in another thread, I find a function, calling a method which seems to contain the name of the unit test I'm running.
Although I know which test is failing, it's based on hunches and on dumpfiles I should even not generate, so I'm looking for another solution:
In the function TEST_METHOD in the file "c:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\VC\Auxiliary\VS\UnitTest\include\CppUnitTest.h", I've tried to add the following lines:
cout << "Test : ";\
cout << methodName;\
cout << "\n";\
I was hoping that this would show every test I wanted to run, but instead I get the error message that this is wrong (also using std::cout and OutputDebugString() function seems not to be allowed).
Hence my question: does anybody know a way to find out, in case one of my unit tests makes my test environment crash, how can I find out which test this is, without needing to generate and debug the Visual Studio dumpfile?
For your information: looking in the "Test Explorer" is not helping: I have a list of disabled tests, a list of successful ones, and a list of some which are not finished, and my failing test is not the first of the "not finished" ones.
Found it: I've added the following line in the definition of TEST_METHOD():
Microsoft::VisualStudio::CppUnitTestFramework::Logger::WriteMessage(L#methodName);\

vs 2013 : breakpoint into cppunittest test throws exception

I am testing my c++11 static lib in vs 2013 environment.
I followed this nice tutorial and testing + code coverage are working fine.
Now I need step-by-step : I added breakpoints and executed the "Debug Selected Test" command and I get the following message : vstest.executionengine.exe has triggered a breakpoint and the callstack brings me at CppUnitTest.h:465 : (static_cast<ThisClass *>(this)->*method2)();, eg at the root call of the method I want to break into. No way to see the code inside this call.
My question : how to break into my code during debugging Ms cpp unit test ?
I found the problem. Some breakpoints were activated inside the static lib used by the test dll. It seems breakpoints inside static lib generates something wrong for the test framework.
To reproduce :
create c++ static lib project with a simple function, int foo(){ return 0;}
create a test-dll project
add a test function which calls foo
set a breakpoint in foo
execute "run selected test" : it will work
execute "debug selected test" : it will block just before calling the test-method test-generated class.
I am still interested in explaining this non-intuitive behaviour.

How to run tests in Nemerle project

How do I run tests which will test my nemerle code. So for example, I've a Calculator class and a CalculatorTests class in a nemerle project. I have already added a reference to nunit using package manager ("install-package nunit"). Now NUnit is available in nemerle project.
After writing following code
[TestFixture]
class CalculatorTests
{
[Test]
MyTest() : void
{
def result = Calculator().Add( 1 );
Assert.AreEqual( 2, result );
}
}
I tried to use TestDriven.net visual studio add-in to run the test but couldn't able to. Can someone tell me how to run tests in nemerle or do i have to write code to run all tests when executing a console app?
Maybe it caused by NUnit runs under .Net 2.0 runtime. Try to set a runtime version in the NUnit command line.

Unit Testing for Windows Phone 7 - App does not launch correctly

I am developing a Wp7-App and I want to start Unit Testing. I used the Template from Visual Studio 2010 to create a Windows Phone 7.1 UnitTest-Project and I added the required Assemblies via Nu-Manager.
I can't start the project in emulator or on a real device. I get a blank loading-screen and this error message:
A first chance exception of type 'System.Collections.Generic.KeyNotFoundException' occurred in mscorlib.dll
Is this a known error? Is there a workaround?
Thanks!
The standard VS Unit test template won't work for WP7. You should look at these links:
http://channel9.msdn.com/Events/MIX/MIX10/CL59
and
http://www.jeff.wilcox.name/2011/06/updated-ut-mango-bits/
I have a Silverlight 4 Test Project using the Jeff Wilcox assemblies and it works fine for my WP7 tests. I use [TestClass] and [TestMethod] attributes and these namespaces inside my tests:
using Microsoft.Silverlight.Testing; using
Microsoft.VisualStudio.TestTools.UnitTesting;
Within the App.xaml.cs file there is minimal code and the following starts it all off:
private void Application_Startup(object sender, StartupEventArgs e)
{
RootVisual = UnitTestSystem.CreateTestPage();
}