请问被测函数中含有断言时,该如何测试?
各位大侠,我最近刚开始接触单元测试,用得工具是CPPUNIT,现在遇到一难题,还请各位帮忙,谢谢了。被测函数:获得当前矩阵的指定行向量
Matrix3x3:: Vertex3d GetRowVector(int nRow) const
{
ASSERT(nRow < m_iDimM && nRow > -1);
return Vertex3d((*this),(*this),(*this));
}
我写的测试用例:
void Matrix3x3TestCase::testGetColVector()
{
Matrix3x3 mtr3x31(1.0,2.0,3.0,4.0,5.0,6.0,7.0,8.0,9.0);
Vertex3d vtx1=mtr3x31.GetColVector(0);
CPPUNIT_ASSERT_EQUAL(1.0,vtx1.x);
CPPUNIT_ASSERT_EQUAL(4.0,vtx1.y);
CPPUNIT_ASSERT_EQUAL(7.0,vtx1.z);
Vertex3d vtx2=mtr3x31.GetColVector(1);
CPPUNIT_ASSERT_EQUAL(2.0,vtx2.x);
CPPUNIT_ASSERT_EQUAL(5.0,vtx2.y);
CPPUNIT_ASSERT_EQUAL(8.0,vtx2.z);
Vertex3d vtx3=mtr3x31.GetColVector(2);
CPPUNIT_ASSERT_EQUAL(3.0,vtx3.x);
CPPUNIT_ASSERT_EQUAL(6.0,vtx3.y);
CPPUNIT_ASSERT_EQUAL(9.0,vtx3.z);
// Vertex3d vtx4;
// vtx4=mtr3x31.GetColVector(3);
// Vertex3d vtx5;
// vtx5=mtr3x31.GetColVector(-1);
}
请问,对于输入的行号为3或者-1这一类不符合要求的数字时,这类异常应该如何捕获呢?我不会在cppunit中捕获异常用例出错情况,还请各位指导!:handshake
[ 本帖最后由 贝壳里的海 于 2009-7-16 22:33 编辑 ]
页:
[1]