Thread: Visual Studio: simple test case

  1. #1
    Registered User
    Join Date
    Mar 2011
    Posts
    19

    Visual Studio: simple test case

    hi all,

    I am new to c++ and is trying to figure out how unit testing works in Visual Studio. The firt problem i have, is that my test class cannot find the class i want to instantiate.

    The program i am testing has a class called Cat_Population_Manager, and the test code is this:
    Code:
    #include "stdafx.h"
    
    using namespace System;
    using namespace System::Text;
    using namespace System::Collections::Generic;
    using namespace	Microsoft::VisualStudio::TestTools::UnitTesting;
    
    namespace CatTesting
    {
    	[TestClass]
    	public ref class Cat_Test
    	{
    	public: 
    		[TestMethod]
    		void TestMethod1()
    		{
    			Cat_Population_Manager manager;
    			Assert.IsNotNull(manager);
    		}
    	};
    }
    And the error goes like this:
    1>------ Build started: Project: CatTesting, Configuration: Debug Win32 ------
    1> Cat_Test.cpp
    1>Cat_Test.cpp(17): error C2065: 'Cat_Population_Manager' : undeclared identifier
    1>Cat_Test.cpp(17): error C2146: syntax error : missing ';' before identifier 'manager'
    1>Cat_Test.cpp(17): error C2065: 'manager' : undeclared identifier
    1>Cat_Test.cpp(18): error C2143: syntax error : missing ';' before '.'
    1>Cat_Test.cpp(18): error C2143: syntax error : missing ';' before '.'
    ========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

    So Cat_Population_Manager is undeclared :-(
    Have tried for two days now, to make this work, but cant figure out how to declare it.

    Please help me...

  2. #2
    Registered User
    Join Date
    Aug 2010
    Location
    Poland
    Posts
    733
    You need to include additional header, which contains Cat_Population_Manager definition.

  3. #3
    Registered User
    Join Date
    Mar 2011
    Posts
    19
    Quote Originally Posted by kmdv View Post
    You need to include additional header, which contains Cat_Population_Manager definition.
    Do i simple write: #include "Cat_Population_Manager.h"
    because it will not except this. It makes a fatal error on that line.

    I cant understand it. What am i doing wrong??? Do i somehow have to tell VS where to find this file Cat_Population_Manager.h ?

  4. #4
    Programming King Mr.777's Avatar
    Join Date
    Mar 2011
    Location
    Middle of NoWhere
    Posts
    320
    Put your header file in your project and then do
    Code:
    #include "your_Class_Name.h"
    I don't care if someone doesn't like me, i was not put on earth to entertain everyone.

    No King, no Queen, I am the ACE of battle.

  5. #5
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Visual Studio only contains tests for managed crap. But fear not, for there is a good native alternative. It's called Visual Assert. Try it.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  6. #6
    Registered User
    Join Date
    Mar 2011
    Posts
    19
    Quote Originally Posted by Elysia View Post
    Visual Studio only contains tests for managed crap. But fear not, for there is a good native alternative. It's called Visual Assert. Try it.
    Visual Assert was exactly what i needed. Thank you :-) Should be integrated in the original program and not an add-on.

  7. #7
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Should be, but isn't unfortunately due to Microsoft's thick-headedness. Can't be helped.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. confused
    By alexbcg in forum C Programming
    Replies: 2
    Last Post: 12-07-2010, 05:42 AM
  2. Number to Word (Billions)
    By myphilosofi in forum C Programming
    Replies: 34
    Last Post: 02-04-2009, 02:09 AM
  3. get keyboard and mouse events
    By ratte in forum Linux Programming
    Replies: 10
    Last Post: 11-17-2007, 05:42 PM
  4. ras.h errors
    By Trent_Easton in forum Windows Programming
    Replies: 8
    Last Post: 07-15-2005, 10:52 PM
  5. Learning OpenGL
    By HQSneaker in forum C++ Programming
    Replies: 7
    Last Post: 08-06-2004, 08:57 AM