Title: Theory / Unimportant / CS / Programming / C++ / Manual / Library / GTest
Tags: automatedNewLineAfterCommaSpace declaration todo_declaration
On every note of this deck, unless a note says otherwise:
Page: http://google.github.io/googletest/advanced.html

Instruction: ASSERT_*
Page: http://google.github.io/googletest/primer.html
Effect: A test that is fatal when it fails
Language: c++
Intuition: The next test would make no sens if this current test fail.
Example: Checking a value is non null before accessing it

Instruction: EXPECT_*
Page: http://google.github.io/googletest/primer.html
Effect: A test that is non fatal when it fail
Language: c++
Intuition: The test can still run, other test don't require this particular expectation to hold to make sens

Instruction: EXPECT/ASSERT_*() << foo
Page: http://google.github.io/googletest/primer.html
Effect: print foo if the test fail
Language: c++

Instruction: TEST(foo, bar) {
  body
}
Page: http://google.github.io/googletest/primer.html
Effect: When testing the test suit foo, execute body as a test named bar
Language: C++

Instruction: TEST_F(
  foo,
  bar
) {
  body
}
Page: http://google.github.io/googletest/primer.html
Effect: Execute the test body, with fixture foo and name bar
Language: C++

Instruction: class FooTest : public ::testing::TEST {
 protected:
  void SetUp() override { ... }
  void TearDown() override { ... }
 ...
  declarations
}
Page: http://google.github.io/googletest/primer.html
Meaning: When FooTest is used as a fixture, SetUp is called before the test, TearDown after, and declarations can be used
Language: c++

Instruction: RUN_ALL_TESTS()
Page: http://google.github.io/googletest/primer.html
Language: c++
Returns: 0 if all test succeeds, 1 otherwise  (e.g. shell style )

Typ: AssertionResult
Meaning: Represents the result of an assertion
Page: http://google.github.io/googletest/advanced.html
Language: C++
Context: GTest

Instruction: AssertionSuccess()
Page: http://google.github.io/googletest/advanced.html
Language: C++
Context: GTest
Returns: An AssertionResult to indicate that an assertion has succeeded

Instruction: AssertionFailure()
Page: http://google.github.io/googletest/advanced.html
Language: C++
Context: GTest
Returns: An AssertionResult to indicate that an assertion has failed

Instruction: EXPECT/ASSERT_PRED_FORMATn(
  predicate,
  val1, ...,
  valn
)
Page: http://google.github.io/googletest/advanced.html
Language: C++
Context: GTest
Returns: Execute predicate on the values val1 ... up to valn. Fail if the predicate return an assertion failure

Instruction: EXPECT/ASSERT_THAT(
  value,
  matcher
)
Page: http://google.github.io/googletest/advanced.html
Effect: Apply matcher(value) and fail if it returns an assertion failure
Language: C++
Context: GTest

Instruction: ::testing::StaticAssertType<foo, bar>();
Page: http://google.github.io/googletest/advanced.html
Effect: Test that succeed if foo and bar are the same type
Language: C++
Context: GTest

Instruction: SUCEED()
Page: http://google.github.io/googletest/advanced.html
Effect: A test that always succeed
Language: C++
Context: GTest

Instruction: FAIL()
Page: http://google.github.io/googletest/advanced.html
Effect: A test that always fails
Language: C++
Context: GTest

Instruction: GTEST_SKIP()
Page: http://google.github.io/googletest/advanced.html
Effect: skip the remaining of the test.
Language: C++
Context: GTest

Question: In error message, how does gtest print values
Answer: using PrintTo(value, output_stream) if it is defined in the same namespace as the value class of the object defined
Context: GTest
Answer2: using << otherwise if it is defined
Answer3: printing its bits

Name: A death test
Definition: A test that check that a program terminates without throwing an exception
Page: http://google.github.io/googletest/advanced.html
Context: GTest

Instruction: EXPECT_EXIT(
  foo,
  testing::ExcitedWithCode(code),
  output
)
Page: http://google.github.io/googletest/advanced.html
Effect: Test that check that foo exit with code code and prints output on stderr
Language: c++
Context: GTest

Instruction: EXPECT_EXIT(
  foo,
  testing::KilledBySignal(signal),
  output
)
Page: http://google.github.io/googletest/advanced.html
Effect: Test that check that foo gets killed by signal
Language: c++
Context: GTest

Instruction: ASSERT_DEATH(
  foo,
  output
)
Page: http://google.github.io/googletest/advanced.html
Effect: Test that checks that foo die with the error message output
Language: c++
Context: GTest

Question: What to do when using death test and test fixture
Answer: The fixture name should ends with DeathTest.
Uses
`using FooDeathTest = FooTest` if the same fixture is used by test and death test
Context: GTest

Question: In which order tests are run?
Answer: Test suites ending with DeathTest are run first
Context: GTest

Instruction: SCOPED_TRACE(foo)
Page: http://google.github.io/googletest/advanced.html
Effect: All failure until we leave the current scope will lead to printing foo
Language: c++
Context: GTest
Intuition: Used in a top level test, so that failure in method have an indication of where the test was originally called

Instruction: HasFatalFailure()
Page: http://google.github.io/googletest/advanced.html
Language: c++
Context: GTest
Returns: Whether a fatal failure occured since te test started
Intuition: If the failure occurred in a function call, it allow to discover it and return

Instruction: ReportProperty(
  property_name,
  value
)
Page: http://google.github.io/googletest/advanced.html
Effect: if there is an xml output, it will have property property_name=value
Language: c++
Context: GTest

Instruction: class FooTest : public testing::Test {
 ...
  static void SetUpTestSuite() {
    foo
  }
   ...
}
Page: http://google.github.io/googletest/advanced.html
Meaning: Execute foo before the first call of a test from current FooTest
Language: c++
Context: text fixture, GTest

Instruction: class FooTest : public testing::Test {
 ...
  static void TearDownTestSuite() {
    foo
  }
   ...
}
Page: http://google.github.io/googletest/advanced.html
Meaning: Execute foo after the last call of a test from current FooTest
Language: c++
Context: text fixture, GTest

Instruction: class FooTest : public testing::Test, public testing::TestWithParamInterface<T> {
  ...
}
Page: http://google.github.io/googletest/advanced.html
Meaning: Create a test fixture FooTest that takes parameter of type T
Language: c++
Context: text fixture, GTest
Abbreviation: class FooTest : public testing::TestWithParam<T>

Instruction: TEST_P(
  FooTest,
  TestName
) {
  bar
}
Page: http://google.github.io/googletest/advanced.html
Effect: Execute the test of bar, one by value of fixture FooTest. The value is getten by `GetParam()`
Language: c++
Context: text fixture,
  GTest

Instruction: GetParam()
Page: http://google.github.io/googletest/advanced.html
Language: c++
Context: text fixture, GTest
Returns: The current paramater of the text fixture

Instruction: INSTANTIATE_TEST_SUITE_P(
  name,
  FooTest,
  testing::Values(
    val_1,
    ...,
    val_n
  )
);
Page: http://google.github.io/googletest/advanced.html
Effect: The test pattern FooTest gets values val_1, ..., val_n , and those values are named name
Language: c++
Context: text fixture,
  GTest

Instruction: foo/bar.buz/n
Page: http://google.github.io/googletest/advanced.html
Effect: Represents test buz of fixture bar, with the n-th parameter of the set of parameter named foo
Language: c++
Context: GTest

Question: What occurs if a parametrized test suite has no parameter
Answer: It's a failure, unless GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(FooTest); is called
Context: GTest

Question: What is the point of having multiple INSTANTIATE_TEST_SUITE_P for a single test suite?
Answer: The test name allow to run test for a specific parametrization only
Context: GTest

Name: An abstract test
Definition: A parametrized test whose parameters are not in the test file
Page: http://google.github.io/googletest/advanced.html
Context: GTest
Intuition: allow to test libraries by letting users put test in it

Instruction: using MyTypes = ::testing::Types<type_1,
  ...,
  type_n>;
TYPED_TEST_SUITE(
  FooTest,
  MyTypes
);
Page: http://google.github.io/googletest/advanced.html
Effect: Ensure that test suite FooTest is executed n time, with the type parameters type_i
Language: c++
Context: GTest

Instruction: TYPED_TEST(
  FooTest,
  DoesBlah
) {
 foo
}
Page: http://google.github.io/googletest/advanced.html
Effect: Execute a test foo, where TypeParam is the a type given in a type parameter
Language: c++
Context: GTest