how to use nunit.framework.dll in managed c++

R

Ray Tayek

hi, i am preparing to teach a class in c++ and would like to intoduce
some unit testing. i can make unit tests in c# using this dll and nant
from the command line.

i am using visual c++ 2005 express at home (the labs may have an earlier
version). does anyone know how to tell visual studio to use this dll?

thanks
 
J

Jay B. Harlow [MVP - Outlook]

Have you tried using "Project - References" to add a reference to the
nunit.framework assembly.

Then you should be able to write your text fixtures as public ref classes.

Something like:

using namespace NUnit::Framework;

namespace UnitTests
{
[TestFixture]
public ref class UnitTest
{
public:
UnitTest(void) {}

[Test]
void Test1()
{
Assert::AreEqual(1, 1);
}

};
}

NOTE: The above is C++/CLI syntax, earlier versions use the MC++ syntax.

--
Hope this helps
Jay [MVP - Outlook]
..NET Application Architect, Enthusiast, & Evangelist
T.S. Bradley - http://www.tsbradley.net


| hi, i am preparing to teach a class in c++ and would like to intoduce
| some unit testing. i can make unit tests in c# using this dll and nant
| from the command line.
|
| i am using visual c++ 2005 express at home (the labs may have an earlier
| version). does anyone know how to tell visual studio to use this dll?
|
| thanks
 
G

Gianluca Carucci

It's also possible create a c# project for unit testing with nunit to
testing c++/cli assembly.
Gianluca
 
J

Jay B. Harlow [MVP - Outlook]

Gianluca,
Yep, I'm currently working on a C++/CLI class library.

I use VB in a VS Team System Test Project for unit testing of the library.

I'm thinking of setting up a smaller C# Team Unit Test, simply to ensure
that either language use of the library makes sense.

I like the idea I can use another language for unit testing, as it helps
ensure the use of the library makes sense in those other languages.

--
Hope this helps
Jay [MVP - Outlook]
..NET Application Architect, Enthusiast, & Evangelist
T.S. Bradley - http://www.tsbradley.net


| It's also possible create a c# project for unit testing with nunit to
| testing c++/cli assembly.
| Gianluca
|
|
 
R

Ray Tayek

Have you tried using "Project - References" to add a reference to the
nunit.framework assembly.

that part usually works.
using namespace NUnit::Framework;

namespace UnitTests
{
[TestFixture] ....

NOTE: The above is C++/CLI syntax, earlier versions use the MC++ syntax.

if i add the cpp sample nunit stuff, it will compile. but the nunit gui
complains.

neither vs 2003 at home nor in the labs will opem the sample projects
that come with the nunit sample.

the code below will compile, but running nunit gui on the exe blows with
an "unverifyable ..." or some other cryptic message. the nunit gui
complains about this also. i've gone through 2.2.[56] 1.1/2.0 verisons.
some versions of nunit were able to run their own tests. i had .net 2.0
installled at home, but removed it. this is a nightmare :(

it's probeblay some versioning issue, but i am new to the visual
studio/.net environement (mostly eclipse/java). i am stuck with vs 2003
and .net 1.1 in the labs at school.

any pointers will be appreciated.

#include "stdafx.h"
#using <mscorlib.dll>
using namespace System;
using namespace NUnit::Framework;
namespace NUnitSamples {
[TestFixture]
public __gc class SimpleCPPSample {
public:
[SetUp] void Init() {}
[Test] void Add() {}
};
}
int _tmain() { Console::WriteLine(S"Hello World"); return 0; }
 
J

Jay B. Harlow [MVP - Outlook]

| the code below will compile, but running nunit gui on the exe blows with
| an "unverifyable ..." or some other cryptic message. the nunit gui
| complains about this also. i've gone through 2.2.[56] 1.1/2.0 verisons.
| some versions of nunit were able to run their own tests. i had .net 2.0
| installled at home, but removed it. this is a nightmare :(
Ah! there's the rub!

In VS 2005 you would need to use /clr:pure which creates Pure & Verifiable
MSIL code.

http://msdn2.microsoft.com/85344whh(en-US,VS.80).aspx

Right now I don't see a VS 2003 equivalent:

http://msdn.microsoft.com/msdnmag/issues/04/05/VisualC2005/

Suggests that "Visual Studio .NET 2003 rarely produced verifiable code, and
even when it did, the effort it took in nontrivial cases was often
significant"...

| int _tmain() { Console::WriteLine(S"Hello World"); return 0; }
I suspect this is causing unverifiable code.

The following sample seems to work:

using namespace System;
using namespace NUnit::Framework;

namespace CUnitTest
{
[TestFixture] public __gc class Class1
{
public:
[SetUp] void Init() {}
[Test] void Add()
{
Assert::IsTrue(false);
}
};
}


--
Hope this helps
Jay [MVP - Outlook]
..NET Application Architect, Enthusiast, & Evangelist
T.S. Bradley - http://www.tsbradley.net


| In article <[email protected]>,
| (e-mail address removed) says...
| > Have you tried using "Project - References" to add a reference to the
| > nunit.framework assembly.
|
| that part usually works.
|
| > using namespace NUnit::Framework;
| >
| > namespace UnitTests
| > {
| > [TestFixture]
| ...
| >
| > NOTE: The above is C++/CLI syntax, earlier versions use the MC++ syntax.
| >
|
| if i add the cpp sample nunit stuff, it will compile. but the nunit gui
| complains.
|
| neither vs 2003 at home nor in the labs will opem the sample projects
| that come with the nunit sample.
|
| the code below will compile, but running nunit gui on the exe blows with
| an "unverifyable ..." or some other cryptic message. the nunit gui
| complains about this also. i've gone through 2.2.[56] 1.1/2.0 verisons.
| some versions of nunit were able to run their own tests. i had .net 2.0
| installled at home, but removed it. this is a nightmare :(
|
| it's probeblay some versioning issue, but i am new to the visual
| studio/.net environement (mostly eclipse/java). i am stuck with vs 2003
| and .net 1.1 in the labs at school.
|
| any pointers will be appreciated.
|
| #include "stdafx.h"
| #using <mscorlib.dll>
| using namespace System;
| using namespace NUnit::Framework;
| namespace NUnitSamples {
| [TestFixture]
| public __gc class SimpleCPPSample {
| public:
| [SetUp] void Init() {}
| [Test] void Add() {}
| };
| }
| int _tmain() { Console::WriteLine(S"Hello World"); return 0; }
 
R

Ray Tayek

| the code below will compile, but running nunit gui on the exe blows with
| an "unverifyable ..." or some other cryptic message. ...

In VS 2005 you would need to use /clr:pure which creates Pure & Verifiable
MSIL code.

ah, that's good to know.

i have managed to get nunit to be stabe in the labs. using nuniy 2.6 for
..net 1.1 and make sure the code is in a dll.

thanks
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top