views:

181

answers:

2

I'm using Visual Studio 2008's built in testing framework in my Visual C++ project. I'm adding a new Test Project, then a new Unit Test. However, I can't use any of the functions provided by Assert. Assert shows up in the Intellisense, but I can't do anything with it. I've done unit tests fine in Visual C#. Am I forgetting to do anything?

EDIT: There isn't much code because everything I'm doing is auto-generated by Visual Studio 2008. Here are the steps I'm doing:

  1. File -> New Project -> Visual C++ -> General -> Empty Project
  2. Right click solution in Solution Explorer -> Add -> New Project...
  3. Visual C++ -> Test -> Test Project
  4. Open UnitTest1.cpp (auto-generated)
  5. Go to TestMethod1()

From here, when I try to use the Assert class (like Assert.AreEqual), I can't do it. If I do the same in a Visual C# project, it works fine.

A: 

See http://msdn.microsoft.com/en-us/library/ms243171%28VS.80%29.aspx

Are you trying to write tests in [unmanaged] C++? If so, you could use CppUnit.

If you're trying to do it in managed C++, are you referencing the Microsoft.VisialStudio.QualityTools assembly?

If not, the assert or Assert you're seeing are probably the standard library and MFC things respectively?

You're not giving us much to go on. Sample? Project type you used to create the project?

Ruben Bartelink
MSVC comes with a unit testing framework, which, like all unit testing libraries, supplies a collection of Assert functions.
jalf
@jalf: Managed C++ or not? The questioner didnt say? How do you know? Got a better answer?
Ruben Bartelink
@jalf: Got any info on this "MSVC unit testing framework?"
Ruben Bartelink
http://msdn.microsoft.com/en-us/library/ms243171%28VS.80%29.aspx - and while managed/native might be relevant to figuring out the OP's question, the framework can test both (although the tests have to be written in managed)
jalf
@jalf: I posted the same link in my edited answer. It sounds to me like the questioner is trying to write tests in managed C++ and is seeing an [aA]ssert of some kind and thinking they're on the right track. That's not possible with MSTest. If this answer is really misleading and worth of your -1, I'll delete it. But I'd love to understand what I'm mising here in terms of helping the questioner. For instance, when you say "MSVC comes with" are you referring to something C++-specific or just the .NET Microsoft.VisualStudio.QualityTools library? It would be nice if the questioner answered :D
Ruben Bartelink
+2  A: 

AreEqual is a static method in Assert class. So use "Assert::AreEqual(...)"

pk
Thank you! Just the answer I needed.
garsh0p