sample6_unittest.cc (googletest-release-1.11.0) | : | sample6_unittest.cc (googletest-release-1.12.0) | ||
---|---|---|---|---|
skipping to change at line 35 | skipping to change at line 35 | |||
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | |||
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | |||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |||
// This sample shows how to test common properties of multiple | // This sample shows how to test common properties of multiple | |||
// implementations of the same interface (aka interface tests). | // implementations of the same interface (aka interface tests). | |||
// The interface and its implementations are in this header. | // The interface and its implementations are in this header. | |||
#include "prime_tables.h" | #include "prime_tables.h" | |||
#include "gtest/gtest.h" | #include "gtest/gtest.h" | |||
namespace { | namespace { | |||
// First, we define some factory functions for creating instances of | // First, we define some factory functions for creating instances of | |||
// the implementations. You may be able to skip this step if all your | // the implementations. You may be able to skip this step if all your | |||
// implementations can be constructed the same way. | // implementations can be constructed the same way. | |||
template <class T> | template <class T> | |||
PrimeTable* CreatePrimeTable(); | PrimeTable* CreatePrimeTable(); | |||
template <> | template <> | |||
skipping to change at line 153 | skipping to change at line 152 | |||
// How can you write the tests without committing to the type | // How can you write the tests without committing to the type | |||
// parameters? That's what "type-parameterized tests" can do for you. | // parameters? That's what "type-parameterized tests" can do for you. | |||
// It is a bit more involved than typed tests, but in return you get a | // It is a bit more involved than typed tests, but in return you get a | |||
// test pattern that can be reused in many contexts, which is a big | // test pattern that can be reused in many contexts, which is a big | |||
// win. Here's how you do it: | // win. Here's how you do it: | |||
// First, define a test fixture class template. Here we just reuse | // First, define a test fixture class template. Here we just reuse | |||
// the PrimeTableTest fixture defined earlier: | // the PrimeTableTest fixture defined earlier: | |||
template <class T> | template <class T> | |||
class PrimeTableTest2 : public PrimeTableTest<T> { | class PrimeTableTest2 : public PrimeTableTest<T> {}; | |||
}; | ||||
// Then, declare the test case. The argument is the name of the test | // Then, declare the test case. The argument is the name of the test | |||
// fixture, and also the name of the test case (as usual). The _P | // fixture, and also the name of the test case (as usual). The _P | |||
// suffix is for "parameterized" or "pattern". | // suffix is for "parameterized" or "pattern". | |||
TYPED_TEST_SUITE_P(PrimeTableTest2); | TYPED_TEST_SUITE_P(PrimeTableTest2); | |||
// Next, use TYPED_TEST_P(TestCaseName, TestName) to define a test, | // Next, use TYPED_TEST_P(TestCaseName, TestName) to define a test, | |||
// similar to what you do with TEST_F. | // similar to what you do with TEST_F. | |||
TYPED_TEST_P(PrimeTableTest2, ReturnsFalseForNonPrimes) { | TYPED_TEST_P(PrimeTableTest2, ReturnsFalseForNonPrimes) { | |||
EXPECT_FALSE(this->table_->IsPrime(-5)); | EXPECT_FALSE(this->table_->IsPrime(-5)); | |||
End of changes. 2 change blocks. | ||||
3 lines changed or deleted | 1 lines changed or added |