1 // Copyright 2018 The Fuchsia Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #pragma once
6 
7 namespace zxtest {
8 // Forward declaration.
9 class TestCase;
10 class TestInfo;
11 
12 // Allows user to listen for lifecycle events. This allows injecting code at specific
13 // instants, for example when there is a global set up and tear down for a library,
14 // that is done at process start up.
15 // This interface mimicks gTest EventObserver, all methods are stubbed with empty body,
16 // so implementing classes, only override those they are interested in.
17 //
18 // Note: This interface will be expanded incrementally in a series of patches,
19 // so it becomes easier to review.
20 class LifecycleObserver {
21 public:
22     virtual ~LifecycleObserver() = default;
23 
24     // Reports before every TestCase is set up.
OnTestCaseStart(const TestCase & test_case)25     virtual void OnTestCaseStart(const TestCase& test_case) {}
26 
27     // Reports before every test starts.
OnTestStart(const TestCase & test_case,const TestInfo & test)28     virtual void OnTestStart(const TestCase& test_case, const TestInfo& test) {}
29 
30     // Reports before every test starts.
OnTestSkip(const TestCase & test_case,const TestInfo & test)31     virtual void OnTestSkip(const TestCase& test_case, const TestInfo& test) {}
32 
33     // Reports before every TestCase is set up.
OnTestFailure(const TestCase & test_case,const TestInfo & test)34     virtual void OnTestFailure(const TestCase& test_case, const TestInfo& test) {}
35 
36     // Reports before every TestCase is set up.
OnTestSuccess(const TestCase & test_case,const TestInfo & test)37     virtual void OnTestSuccess(const TestCase& test_case, const TestInfo& test) {}
38 
39     // Reports before every TestCase is torn down.
OnTestCaseEnd(const TestCase & test_case)40     virtual void OnTestCaseEnd(const TestCase& test_case) {}
41 };
42 
43 } // namespace zxtest
44