-
Notifications
You must be signed in to change notification settings - Fork 0
Unit Tests
Nathan Floris Copier edited this page Mar 10, 2016
·
2 revisions
Any *.cpp file placed in the /tests/Specs directory will automatically be ran by gTest without any extra configuration. To create a test suite, create a *.cpp file somewhere in that directory, include "gtest/gtest.h", and define a class that extends from ::testing::Test
.
Example suite:
#include <gtest/gtest.h>
#include <path/to/controller/being/tested.h>
class SampleSuite : public ::testing::Test {}
To add a spec, use the TEST
macro, passing in the suite class and a name for the spec.
Sample spec:
TEST(SampleSuite, SampleSpec) {
//Do testing stuff
}
GTest has many built in macros to handle your specs' expectations.
Complete example:
#include <gtest/gtest.h>
class SampleSuite : public ::testing::Test {}
TEST(SampleSuite, SampleSpec1) {
EXPECT_TRUE(false); // Will fail
}
TEST(SampleSuite, SampleSpec2) {
EXPECT_FALSE(false); // Will pass
}
To run this, it should be as simple as
cmake
make Specs
./Specs
To be determined...