I am trying to create Unit Tests in Visual Studios 2012 using a Native Unit Test Project.
This is the test I have:
TEST_METHOD(CalculationsRoundTests)
{
int result = Calculations::Round(1.0);
Assert::AreEqual(1, result);
}
Exporting the Class:
#ifdef EXPORT_TEST_FUNCTIONS
#define MY_CALCULATIONS_EXPORT __declspec(dllexport)
#else
#define MY_CALCULATIONS_EXPORT
#endif
...
class CALCULATIONS_EXPORT Calculations {
...
public:
static int Round(const double& x);
The function itself:
int Calculations::Round(const double& x)
{
int temp;
if (floor(x) + 0.5 > x)
temp = floor(x);
else
temp = ceil(x);
return int(temp);
}
However, the test nearly always fails with error code c0000005 (Access Violation). The test will fail the first time that x, or any other variable that may be declared in the function, is used.
I followed the instructions at Unresolved externals when compiling unit tests for Visual C++ 2012
On the 'Advanced Configuration' dialog, set the 'Maximum Userdump Limit' to 25, then click the 'Exceptions' button. Click 'Add Exception' Select C0000005 in the list, then set the 'Action Type' to 'Full Userdump' and the 'Action Limit' to 25. Click 'OK', then 'Save and Close' and finally click 'Next'
A C0000005 error is memory error. Specifically, a C0000005 error is an access violation error caused by a buffer overrun.
Run tests in Test Explorer If Test Explorer is not visible, choose Test on the Visual Studio menu, choose Windows, and then choose Test Explorer (or press Ctrl + E, T). As you run, write, and rerun your tests, the Test Explorer displays the results in a default grouping of Project, Namespace, and Class.
This is a known bug. Unfortunately, Microsoft considers this as "Won't Fix".
In short, there are two workarounds:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With