Hi
I want to learn CppUnit. I have tried to use CppUnit 1.8 version with Microsoft Visual studio 6.0. if I create new project, which are the setting I need to change. How will i decide, whether i have to use "TestFixture.h" or "TestCase.h". What is the difference between Hirearchy and Host App?
Please Inform me about CppUnit how can i use it effectively.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
While running the the example it is giving
Caught execption in testCoustructor.
but i have tried the example with out CppUnit
getstuName is giving expected Output.
Please tell me whether it will work or not.
If you require more details then please tell me.
Thanks & Regards
Ritesh
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
yes, you can even compare two strings with CPPUNIT_ASSERT_EQUAL, but something (the compiler?) isn't smart enough to do type conversions for you, so the two arguments must be the same type.
Hi
Thanks Tom, but my problem still not resolved. I am sending here full code having same problem in this, inspite of string, I am using unsigned int. Can you tell me, does the function "showrno" is having ant error.
because while running it is giving me "Caught unknown execption"
this function is called in the TestConstructor :
student_rno = stu1->showrno();
Please see to it.
**************************************************
//Student.h
#ifndef Student_h
#define Student_h
#include<iostream.h>
class student
{
protected :
unsigned int rno;
public :
// unsigned int count;
student ();
student(unsigned int st);
unsigned int showrno();
};
class exam : virtual public student
{
protected :
unsigned int marks1,marks2;
public :
exam(unsigned int m1=0,unsigned int m2=0,unsigned int r=0);
virtual showmarks();
};
class result : public exam
{
protected :
unsigned int total;
public :
result();
result(unsigned int i,unsigned int j,unsigned int k);
virtual showtotal();
// method to test the constructor
void StudentTestCase::testConstructor()
{
unsigned int student_rno=2;
// check that the object is constructed correctly
student_rno = stu1->showrno();
CPPUNIT_ASSERT_EQUAL(unsigned int (1),student_rno);
int main(int argc,char **argv)
{
CppUnit::TextUi::TestRunner runner;
runner.addTest(StudentTestCase::suite());
runner.run();
return 0;
}
**************************************************
I have tried it using main function is returning proper value there.
student_rno = stu1->showrno();
please tell me whats wrong here.
Thanks & Regards
- Ritesh
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Have you put breakpoints in your setup() and teardown() methods to make sure they're doing what you want? Have you inspected what the value of stu1 is when you're running the testConstructor()?
(Hint: you may find that the naming of your setup and teardown routines are such that they aren't overloading the virtuals in TestFixture. Why they chose to name their functions like that is beyond me, but they did...)
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hi
Till now i have seen my out put on command line for CppUnit. Now i want to learn with HostApps. I have tried this by including my files in the example folder. I want to do it out side the cppunit folder. it is asking for the main. But in the Example\msvc6\hostapp there is no main, so, how is it calling the ExampleTestCase there? how can i resolve this problem?
Please resolve my query.
Thanks & Regards
- Ritesh
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hi
I want to learn CppUnit. I have tried to use CppUnit 1.8 version with Microsoft Visual studio 6.0. if I create new project, which are the setting I need to change. How will i decide, whether i have to use "TestFixture.h" or "TestCase.h". What is the difference between Hirearchy and Host App?
Please Inform me about CppUnit how can i use it effectively.
...maybe I really should try to write some step-by-steps. :)
search for "CWinApp" in the help forum to find my mail on the minimal setup for a test project (for project settings take the default).
Use TestFixture.h.
Wolfgang
Hi
Can I compare 2 string with
CPPUNIT_ASSERT. example
This example is from the crash course.
testConstructor
std::string student_name = stu1->getStuName
();
CPPUNIT_ASSERT("Tan Meng
Chee",student_name );
Or
CPPUNIT_ASSERT("Tan Meng
Chee" == student_name );
While running the the example it is giving
Caught execption in testCoustructor.
but i have tried the example with out CppUnit
getstuName is giving expected Output.
Please tell me whether it will work or not.
If you require more details then please tell me.
Thanks & Regards
Ritesh
yes, you can even compare two strings with CPPUNIT_ASSERT_EQUAL, but something (the compiler?) isn't smart enough to do type conversions for you, so the two arguments must be the same type.
std::string myName("Tom Plunket");
CPPUNIT_ASSERT_EQUAL(std::string("Tom Plunket", myName);
Hi
Thanks Tom, but my problem still not resolved. I am sending here full code having same problem in this, inspite of string, I am using unsigned int. Can you tell me, does the function "showrno" is having ant error.
because while running it is giving me "Caught unknown execption"
this function is called in the TestConstructor :
student_rno = stu1->showrno();
Please see to it.
**************************************************
//Student.h
#ifndef Student_h
#define Student_h
#include<iostream.h>
class student
{
protected :
unsigned int rno;
public :
// unsigned int count;
student ();
student(unsigned int st);
unsigned int showrno();
};
class exam : virtual public student
{
protected :
unsigned int marks1,marks2;
public :
exam(unsigned int m1=0,unsigned int m2=0,unsigned int r=0);
virtual showmarks();
};
class result : public exam
{
protected :
unsigned int total;
public :
result();
result(unsigned int i,unsigned int j,unsigned int k);
virtual showtotal();
};
#endif
**************************************************
//Student.cpp
#include"Student.h"
student::student ()
{
rno=0;
}
student::student(unsigned int st)
{
rno=st;
}
unsigned int student::showrno()
{
return rno;
}
exam::exam(unsigned int m1,unsigned int m2,unsigned int r) : student(r)
{
marks1=m1;
marks2=m2;
}
result::result()
{
total=0;
}
result::result(unsigned int i,unsigned int j,unsigned int k):exam(i,j),student(k)
{
}
**************************************************
//TestStudent.h
#ifndef CPP_UNIT_TESTSTUDENT_H
#define CPP_UNIT_TESTSTUDENT_H
#include "Student.h"
#include "cppunit/extensions/HelperMacros.h"
class StudentTestCase : public CppUnit::TestFixture
{
CPPUNIT_TEST_SUITE( StudentTestCase );
CPPUNIT_TEST( testConstructor );
CPPUNIT_TEST_SUITE_END();
private:
result *stu1,*stu2;
public:
void setup();
void teardown();
void testConstructor();
};
#endif
**************************************************
//TestStudent.cpp
#include "TestStudent.h"
//#include<string>
CPPUNIT_TEST_SUITE_REGISTRATION( StudentTestCase );
void StudentTestCase::setup()
{
// create a student object
stu1=new result(1,1,1);
stu2=new result(2,2,2);
}
void StudentTestCase::teardown()
{
delete stu1;
delete stu2;
}
// method to test the constructor
void StudentTestCase::testConstructor()
{
unsigned int student_rno=2;
// check that the object is constructed correctly
student_rno = stu1->showrno();
CPPUNIT_ASSERT_EQUAL(unsigned int (1),student_rno);
}
**************************************************
//main.cpp
#include"TestStudent.h"
#include"c:\\cppunit-1.8.0\\include\\cppunit\\ui\\text\\TestRunner.h"
int main(int argc,char **argv)
{
CppUnit::TextUi::TestRunner runner;
runner.addTest(StudentTestCase::suite());
runner.run();
return 0;
}
**************************************************
I have tried it using main function is returning proper value there.
student_rno = stu1->showrno();
please tell me whats wrong here.
Thanks & Regards
- Ritesh
Have you put breakpoints in your setup() and teardown() methods to make sure they're doing what you want? Have you inspected what the value of stu1 is when you're running the testConstructor()?
(Hint: you may find that the naming of your setup and teardown routines are such that they aren't overloading the virtuals in TestFixture. Why they chose to name their functions like that is beyond me, but they did...)
Hi
Thanks Tom my problem is resolved. There was problem with setUp.
Thanks & Regards
- Ritesh
Hi
Till now i have seen my out put on command line for CppUnit. Now i want to learn with HostApps. I have tried this by including my files in the example folder. I want to do it out side the cppunit folder. it is asking for the main. But in the Example\msvc6\hostapp there is no main, so, how is it calling the ExampleTestCase there? how can i resolve this problem?
Please resolve my query.
Thanks & Regards
- Ritesh