Answer the question
In order to leave comments, you need to log in
How to initialize a checkable object for google tests?
I set up a project in CLion, connected a module from Google for testing.
And I don't quite understand how can I test objects?
For example, I have a matrix
I call:
#include <iostream>
#include <gtest/gtest.h>
#include <gmock/gmock.h>
int main(int argc, char* argv[]) {
// Running Unit-tests
testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}
#include <gtest/gtest.h>
#include <gmock/gmock.h>
#include "Matrix.h"
using namespace std;
// A new one of these is created for each test
class VectorTest : public testing::Test
{
public:
Matrix userMatrix;
Matrix testMatrix;
virtual void SetUp() {
int row;
int col;
std::cout << "Enter matrix size (col x row)\n";
std::cout << "Row:"; std::cin >> row;
std::cout << "Col:"; std::cin >> col;
std::cout << "User enter matrix ( " << col << " x " << row << " )\n";
// Create stack object instance
userMatrix(col, row);
std::cout << "Now, let's init matrix:...\n";
// User input matrix instance
std::cin >> userMatrix;
std::cout << "After initialization:\n";
std::cout << userMatrix;
testMatrix(col, row);
std::cout << "Let's init tester matrix\n";
std::cin >> testMatrix;
std::cout << "Result of tested matrix initialization \n" << testMatrix;
}
virtual void TearDown()
{
}
};
Answer the question
In order to leave comments, you need to log in
When you want to test an object, you write a test for it.
TEST( TestStaticString, GetChar )
{
using TestString = Black::StaticString<'A', 'B', 'C'>;
EXPECT_EQ( 'A', TestString::GetChar( 0 ) );
EXPECT_EQ( 'B', TestString::GetChar( 1 ) );
EXPECT_EQ( 'C', TestString::GetChar( 2 ) );
}
TEST
is a macro that expands into a special binding for your test. Its first parameter is the name of the test case, the second is the name of the test. EXPECT_*
and ASSERT_*
. VectorTest
is a test fixture. You can apply it to your tests using the macro TEST_F
. Read about ityou can here . Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question