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

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Ray Tayek

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

    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
  • Jay B. Harlow [MVP - Outlook]

    #2
    Re: how to use nunit.framework .dll in managed c++

    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::Framewor k;

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

    [Test]
    void Test1()
    {
    Assert::AreEqua l(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


    "Ray Tayek" <rtayek.no@spam .comcast.net> wrote in message
    news:MPG.1e38f1 492cf0812989681 @msnews.microso ft.com...
    | 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


    Comment

    • Gianluca Carucci

      #3
      Re: how to use nunit.framework .dll in managed c++

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


      Comment

      • Jay B. Harlow [MVP - Outlook]

        #4
        Re: how to use nunit.framework .dll in managed c++

        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


        "Gianluca Carucci" <rucka@removeme tiscalinet.it> wrote in message
        news:%23WRb$2KJ GHA.344@TK2MSFT NGP11.phx.gbl.. .
        | It's also possible create a c# project for unit testing with nunit to
        | testing c++/cli assembly.
        | Gianluca
        |
        |


        Comment

        • Ray Tayek

          #5
          Re: how to use nunit.framework .dll in managed c++

          In article <eo8y5bgHGHA.31 16@TK2MSFTNGP15 .phx.gbl>,
          Jay_Harlow_MVP@ tsbradley.net says...[color=blue]
          > Have you tried using "Project - References" to add a reference to the
          > nunit.framework assembly.[/color]

          that part usually works.
          [color=blue]
          > using namespace NUnit::Framewor k;
          >
          > namespace UnitTests
          > {
          > [TestFixture][/color]
          ....[color=blue]
          >
          > NOTE: The above is C++/CLI syntax, earlier versions use the MC++ syntax.
          >[/color]

          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 "unverifyab le ..." 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::Framewor k;
          namespace NUnitSamples {
          [TestFixture]
          public __gc class SimpleCPPSample {
          public:
          [SetUp] void Init() {}
          [Test] void Add() {}
          };
          }
          int _tmain() { Console::WriteL ine(S"Hello World"); return 0; }

          Comment

          • Jay B. Harlow [MVP - Outlook]

            #6
            Re: how to use nunit.framework .dll in managed c++

            | the code below will compile, but running nunit gui on the exe blows with
            | an "unverifyab le ..." 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.



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

            Learn with interactive lessons and technical documentation, earn professional development hours and certifications, and connect with the community.


            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::WriteL ine(S"Hello World"); return 0; }
            I suspect this is causing unverifiable code.

            The following sample seems to work:

            using namespace System;
            using namespace NUnit::Framewor k;

            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


            "Ray Tayek" <rtayek.no@spam .comcast.net> wrote in message
            news:MPG.1e4da0 c5395f3fa698968 6@msnews.micros oft.com...
            | In article <eo8y5bgHGHA.31 16@TK2MSFTNGP15 .phx.gbl>,
            | Jay_Harlow_MVP@ tsbradley.net says...
            | > Have you tried using "Project - References" to add a reference to the
            | > nunit.framework assembly.
            |
            | that part usually works.
            |
            | > using namespace NUnit::Framewor k;
            | >
            | > 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 "unverifyab le ..." 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::Framewor k;
            | namespace NUnitSamples {
            | [TestFixture]
            | public __gc class SimpleCPPSample {
            | public:
            | [SetUp] void Init() {}
            | [Test] void Add() {}
            | };
            | }
            | int _tmain() { Console::WriteL ine(S"Hello World"); return 0; }


            Comment

            • Ray Tayek

              #7
              Re: how to use nunit.framework .dll in managed c++

              In article <uI$D4SsKGHA.40 44@TK2MSFTNGP10 .phx.gbl>,
              Jay_Harlow_MVP@ tsbradley.net says...[color=blue]
              > | the code below will compile, but running nunit gui on the exe blows with
              > | an "unverifyab le ..." or some other cryptic message. ...
              >
              > In VS 2005 you would need to use /clr:pure which creates Pure & Verifiable
              > MSIL code.[/color]

              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

              Comment

              Working...