aboutsummaryrefslogblamecommitdiffstats
path: root/lib/common_test/doc/src/ct_hooks.xml
blob: b9bc54ff6340c85029dd0c8496755e494d65d48c (plain) (tree)
1
2
3
4
5
6
7
8
9
10
                                       




                                     
                                        


                                                        


                                                                      
 
                                                    
 




                                                                              


                  
                                    






                                            
                              
           
                                               
                                                                            


               




                                                                               
 
                                       
 




                                                                            

           
                                                                     



                                                                           
 






                                                                              
 


                

                                                                           



            
                                                                                                     
                                                          
            



                                        
             
                









                                                                              
                     









                                                                              



             
                                                                                                      





                                                                

                                                                                                              
                                
                                                                                         

                                                     
                                                                                                                                   









































                                                                                  
                                                                                                        



                                                         
                                                                                                                                                                 
                                
                                                                                         




                                                                                      
                                                                                                                                   


                                                                     
                                                                                      


















































                                                                                  
                                                                                                           
                                                        
            









                                                           
             
                
































                                                                                               

             
 
          
                                                                                                                  
                                                       
            








                                                                    
             
                




























                                                                                                

             
 
          
                                                                                                                    
                                                        
            
                                 








                                                             
             
                








                                                                                                     




                                                                             

             
 
          
                                                                                                                           
                                                       
            
                                 








                                                                
             
                








                                                                                                       




                                                                              



             
                                                                                                                          
                                                           
            
                                 








                                                             
             
                









                                                                                                     




                                                                                


                                                                            



             
                                                                                                                                 

                                                          
                                 



















                                                                                                       




                                                                                 



             
                                                                                                                        

                                                          
                                 
                                    
                               



















                                                                                                   





                                                                               



             
                                                                                                                                
                                                         
            
                                 








                                                                
             
                




                                                                                                   
                                                                                                     


                                                                                                   




                                                                                



             
                                                                                                                  
                                                       
            
                                 








                                                             
             
                








                                                                                                     




                                                                            



             
                                                                                                                          
                                                      
            
                                 








                                                                
             
                








                                                                                                       




                                                                             



             
                                                                                                         
                                                       
            








                                                             
             
                








                                                                                                     



             
                                                                                                                 
                                                      
            








                                                                
             
                








                                                                                                       



             
                                                                                                              
                                                           
            
                                 




                                                                                                                                                   
             
                









                                                                                                            
                                                                                                              












                                                                                        




                                                                     



             
                                                                                                              
                                                           
            
                                 




                                                                                                                                                   
             
                








                                                                              
                                                                                                            
                                                                           
                                                                                                              













                                                                                            




                                                                     



             
                                                                
                                                           
            
                                
             
                
                       
 

                                                                       



             
                                                              
                                                                    
            

                            
             
            
                      
        











                                                                                 
           




          
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE erlref SYSTEM "erlref.dtd">

<erlref>
  <header>
    <copyright>
      <year>2010</year><year>2017</year>
      <holder>Ericsson AB. All Rights Reserved.</holder>
    </copyright>
    <legalnotice>
      Licensed under the Apache License, Version 2.0 (the "License");
      you may not use this file except in compliance with the License.
      You may obtain a copy of the License at

          http://www.apache.org/licenses/LICENSE-2.0

      Unless required by applicable law or agreed to in writing, software
      distributed under the License is distributed on an "AS IS" BASIS,
      WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
      See the License for the specific language governing permissions and
      limitations under the License.

    </legalnotice>

    <title>Common Test Hooks</title>
    <prepared>Lukas Larsson</prepared>
    <responsible>Lukas Larsson</responsible>
    <docno></docno>
    <approved></approved>
    <checked></checked>
    <date>2010-12-02</date>
    <rev>PA1</rev>
    <file>ct_hooks.sgml</file>
  </header>
  <module since="OTP R14B02">ct_hooks</module> 
  <modulesummary>A callback interface on top of Common Test.</modulesummary>

  <description>

    <p>The <em>Common Test Hook (CTH)</em> framework allows extensions of the
      default behavior of <c>Common Test</c> by callbacks before and after all
      test suite calls. It is intended for advanced users of <c>Common Test</c>
      who want to abstract out behavior that is common to multiple test suites.
    </p>

    <p>In brief, CTH allows you to:</p>

    <list type="bulleted">
      <item><p>Manipulate the runtime configuration before each suite
        configuration call.</p></item>
      <item><p>Manipulate the return of all suite configuration calls and by
        extension the result of the test themselves.</p></item>
    </list>
    
    <p>The following sections describe the mandatory and optional CTH
      functions that <c>Common Test</c> calls during test execution.
      For more details, see section
      <seealso marker="ct_hooks_chapter">Common Test Hooks</seealso> in the
      User's Guide.</p>

    <p>For information about how to add a CTH to your suite, see section
      <seealso marker="ct_hooks_chapter#installing">Installing a CTH</seealso>
      in the User's Guide.</p>

    <note><p>For a minimal example of a CTH, see section
      <seealso marker="ct_hooks_chapter#example">Example CTH</seealso>
      in the User's Guide.</p></note>

  </description>

  <section>
    <title>Callback Functions</title>
    <p>The following functions define the callback interface for a CTH.</p>
  </section>
  
  <funcs>
    <func>
      <name since="OTP R14B02">Module:init(Id, Opts) -&gt; {ok, State} | {ok, State, Priority}</name>
      <fsummary>Initiates the Common Test Hook.</fsummary>
      <type>
        <v>Id = reference() | term()</v>
        <v>Opts = term()</v>
        <v>State = term()</v>
        <v>Priority = integer()</v>
      </type>
      <desc>	
        <p>MANDATORY</p>

        <p>This function is always called before any other callback function.
          Use it to initiate any common state. It is to return a state for
          this CTH.</p>

        <p><c>Id</c> is either the return value of
          <seealso marker="#Module:id-1"><c>ct_hooks:id/1</c></seealso>,
          or a <c>reference</c> (created using
          <seealso marker="erts:erlang#make_ref-0">erlang:make_ref/0</seealso>
          in ERTS) if
          <seealso marker="#Module:id-1"><c>ct_hooks:id/1</c></seealso>
          is not implemented.</p>

        <p><c>Priority</c> is the relative priority of this hook. Hooks with a
          lower priority are executed first. If no priority is specified, it 
          is set to <c>0</c>.</p>

        <p>For details about when <c>init</c> is called, see section
          <seealso marker="ct_hooks_chapter#scope">CTH Scope</seealso>
          in the User's Guide.</p>    
      </desc>
    </func>

    <func>
      <name since="OTP @OTP-14746@">Module:post_groups(SuiteName, GroupDefs) -&gt; NewGroupDefs</name>
      <fsummary>Called after groups/0.</fsummary>
      <type>
        <v>SuiteName = atom()</v>
        <v>GroupDefs = NewGroupDefs = [Group]</v>
        <v>Group = {GroupName,Properties,GroupsAndTestCases}</v>
        <v>GroupName = atom()</v>
        <v>Properties = [parallel | sequence | Shuffle | {GroupRepeatType,N}]</v>
        <v>GroupsAndTestCases = [Group | {group,GroupName} | TestCase | {testcase,TestCase,TCRepeatProps}]</v>
        <v>TestCase = atom()</v>
	<v>TCRepeatProps = [{repeat,N} | {repeat_until_ok,N} | {repeat_until_fail,N}]</v>
        <v>Shuffle = shuffle | {shuffle,Seed}</v>
        <v>Seed = {integer(),integer(),integer()}</v>
        <v>GroupRepeatType = repeat | repeat_until_all_ok | repeat_until_all_fail | repeat_until_any_ok | repeat_until_any_fail</v>
        <v>N = integer() | forever</v>
      </type>
      <desc>
        <p>OPTIONAL</p>

        <p>This function is called after
          <seealso marker="common_test#Module:groups-0"><c>groups/0</c></seealso>.
	  It is used to modify the test group definitions, for
	  instance to add or remove groups or change group properties.</p>

        <p><c>GroupDefs</c> is what
          <seealso marker="common_test#Module:groups-0"><c>groups/0</c></seealso>
          returned, that is, a list of group definitions.</p>

        <p><c>NewGroupDefs</c> is the possibly modified version of this list.</p>

        <p>This function is called only if the CTH is added before
          <c>init_per_suite</c> is run. For details, see section
          <seealso marker="ct_hooks_chapter#scope">CTH Scope</seealso>
          in the User's Guide.</p>

	<p>Notice that for CTHs that are installed by means of the
	  <seealso marker="common_test#Module:suite-0"><c>suite/0</c></seealso>
	  function, <c>post_groups/2</c> is called before
	  the <seealso marker="#Module:init-2"><c>init/2</c></seealso>
	  hook function. However, for CTHs that are installed by means
	  of the CT start flag,
	  the <seealso marker="#Module:init-2"><c>init/2</c></seealso>
	  function is called first.</p>

	<note>
	  <p>Prior to each test execution, Common Test does a
	    simulated test run in order to count test suites, groups
	    and cases for logging purposes. This causes
	    the <c>post_groups/2</c> hook function to always be called
	    twice. For this reason, side effects are best avoided in
	    this callback.</p>
	</note>
      </desc>
    </func>

    <func>
      <name since="OTP @OTP-14746@">Module:post_all(SuiteName, Return, GroupDefs) -&gt; NewReturn</name>
      <fsummary>Called after all/0.</fsummary>
      <type>
        <v>SuiteName = atom()</v>
	<v>Return = NewReturn = Tests | {skip,Reason}</v>
	<v>Tests = [TestCase | {testcase,TestCase,TCRepeatProps} | {group,GroupName} | {group,GroupName,Properties} | {group,GroupName,Properties,SubGroups}]</v>
	<v>TestCase = atom()</v>
	<v>TCRepeatProps = [{repeat,N} | {repeat_until_ok,N} | {repeat_until_fail,N}]</v>
	<v>GroupName = atom()</v>
	<v>Properties = GroupProperties | default</v>
	<v>SubGroups = [{GroupName,Properties} | {GroupName,Properties,SubGroups}]</v>
	<v>Shuffle = shuffle | {shuffle,Seed}</v>
	<v>Seed = {integer(),integer(),integer()}</v>
	<v>GroupRepeatType = repeat | repeat_until_all_ok | repeat_until_all_fail | repeat_until_any_ok | repeat_until_any_fail</v>
	<v>N = integer() | forever</v>
        <v>GroupDefs = NewGroupDefs = [Group]</v>
        <v>Group = {GroupName,GroupProperties,GroupsAndTestCases}</v>
        <v>GroupProperties = [parallel | sequence | Shuffle | {GroupRepeatType,N}]</v>
        <v>GroupsAndTestCases = [Group | {group,GroupName} | TestCase]</v>
	<v>Reason = term()</v>
      </type>
      <desc>
        <p>OPTIONAL</p>

        <p>This function is called after
          <seealso marker="common_test#Module:all-0"><c>all/0</c></seealso>.
	  It is used to modify the set of test cases and test group to
	  be executed, for instance to add or remove test cases and
	  groups, change group properties, or even skip all tests in
	  the suite.</p>

        <p><c>Return</c> is what
          <seealso marker="common_test#Module:all-0"><c>all/0</c></seealso>
          returned, that is, a list of test cases and groups to be
          executed, or a tuple <c>{skip,Reason}</c>.</p>

        <p><c>GroupDefs</c> is what
          <seealso marker="common_test#Module:groups-0"><c>groups/0</c></seealso>
          or the <c>post_groups/2</c> hook returned, that is, a list
          of group definitions.</p>

        <p><c>NewReturn</c> is the possibly modified version of <c>Return</c>.</p>

        <p>This function is called only if the CTH is added before
          <c>init_per_suite</c> is run. For details, see section
          <seealso marker="ct_hooks_chapter#scope">CTH Scope</seealso>
          in the User's Guide.</p>

	<p>Notice that for CTHs that are installed by means of the
	  <seealso marker="common_test#Module:suite-0"><c>suite/0</c></seealso>
	  function, <c>post_all/2</c> is called before
	  the <seealso marker="#Module:init-2"><c>init/2</c></seealso>
	  hook function. However, for CTHs that are installed by means
	  of the CT start flag,
	  the <seealso marker="#Module:init-2"><c>init/2</c></seealso>
	  function is called first.</p>

	<note>
	  <p>Prior to each test execution, Common Test does a
	    simulated test run in order to count test suites, groups
	    and cases for logging purposes. This causes
	    the <c>post_all/3</c> hook function to always be called
	    twice. For this reason, side effects are best avoided in
	    this callback.</p>
	</note>
      </desc>
    </func>

    <func>
      <name since="OTP R14B02">Module:pre_init_per_suite(SuiteName, InitData, CTHState) -&gt; Result</name>
      <fsummary>Called before init_per_suite.</fsummary>
      <type>
        <v>SuiteName = atom()</v>
        <v>InitData = Config | SkipOrFail</v>
        <v>Config = NewConfig = [{Key,Value}]</v>
        <v>CTHState = NewCTHState = term()</v>
        <v>Result = {Return, NewCTHState}</v>
        <v>Return = NewConfig | SkipOrFail</v>
        <v>SkipOrFail = {fail, Reason} | {skip, Reason}</v>
        <v>Key = atom()</v>
        <v>Value = term()</v>
        <v>Reason = term()</v>
      </type>
      <desc>	
        <p>OPTIONAL</p>

        <p>This function is called before
          <seealso marker="common_test#Module:init_per_suite-1"><c>init_per_suite</c></seealso>
          if it exists. It typically contains initialization/logging that must
          be done before <c>init_per_suite</c> is called. If
          <c>{skip,Reason}</c> or <c>{fail,Reason}</c> is returned,
          <c>init_per_suite</c> and all test cases of the suite are skipped
          and <c>Reason</c> printed in the overview log of the suite.</p>

        <p><c>SuiteName</c> is the name of the suite to be run.</p>

        <p><c>InitData</c> is the original configuration list of the test
          suite, or a <c>SkipOrFail</c> tuple if a previous CTH has returned
          this.</p>

        <p><c>CTHState</c> is the current internal state of the CTH.</p>

        <p><c>Return</c> is the result of the <c>init_per_suite</c> function.
          If it is <c>{skip,Reason}</c> or <c>{fail,Reason}</c>, 
          <seealso marker="common_test#Module:init_per_suite-1"><c>init_per_suite</c></seealso>
          is never called, instead the initiation is considered to be
          skipped or failed, respectively. If a <c>NewConfig</c> list is
          returned,
          <seealso marker="common_test#Module:init_per_suite-1"><c>init_per_suite</c></seealso>
          is called with that <c>NewConfig</c> list. For more details, see
          section <seealso marker="ct_hooks_chapter#pre">Pre Hooks</seealso>
          in the User's Guide.</p>

        <p>This function is called only if the CTH is added before
          <c>init_per_suite is run</c>. For details, see section
          <seealso marker="ct_hooks_chapter#scope">CTH Scope</seealso>
          in the User's Guide.</p>
      </desc>
    </func>

    <func>
      <name since="OTP R14B02">Module:post_init_per_suite(SuiteName, Config, Return, CTHState) -&gt; Result</name>
      <fsummary>Called after init_per_suite.</fsummary>
      <type>
        <v>SuiteName = atom()</v>
        <v>Config = [{Key,Value}]</v>
        <v>Return = NewReturn = Config | SkipOrFail | term()</v>
        <v>SkipOrFail = {fail, Reason} | {skip, Reason} | term()</v>
        <v>CTHState = NewCTHState = term()</v>
        <v>Result = {NewReturn, NewCTHState}</v>
        <v>Key = atom()</v>
        <v>Value = term()</v>
        <v>Reason = term()</v>
      </type>
      <desc>	
        <p>OPTIONAL</p>

        <p>This function is called after
          <seealso marker="common_test#Module:init_per_suite-1"><c>init_per_suite</c></seealso>
          if it exists. It typically contains extra checks to ensure that all
          the correct dependencies are started correctly.</p>

        <p><c>Return</c> is what
          <seealso marker="common_test#Module:init_per_suite-1"><c>init_per_suite</c></seealso>
          returned, that is, <c>{fail,Reason}</c>, <c>{skip,Reason}</c>, a
          <c>Config</c> list, or a term describing how
          <seealso marker="common_test#Module:init_per_suite-1"><c>init_per_suite</c></seealso>
          failed.</p>

        <p><c>NewReturn</c> is the possibly modified return value of
          <seealso marker="common_test#Module:init_per_suite-1"><c>init_per_suite</c></seealso>.
          To recover from a failure in
          <seealso marker="common_test#Module:init_per_suite-1"><c>init_per_suite</c></seealso>,
          return <c>ConfigList</c> with the <c>tc_status</c> element removed.
          For more details, see
          <seealso marker="ct_hooks_chapter#post"> Post Hooks</seealso> in
          section "Manipulating Tests" in the User's Guide.</p>

        <p><c>CTHState</c> is the current internal state of the CTH.</p>

        <p>This function is called only if the CTH is added before or in
          <c>init_per_suite</c>. For details, see section
          <seealso marker="ct_hooks_chapter#scope">CTH Scope</seealso>
          in the User's Guide.</p>
      </desc>
    </func>

    <func>
      <name since="OTP 19.3">Module:pre_init_per_group(SuiteName, GroupName, InitData, CTHState) -&gt; Result</name>
      <fsummary>Called before init_per_group.</fsummary>
      <type>
        <v>SuiteName = atom()</v>
        <v>GroupName = atom()</v>
        <v>InitData = Config | SkipOrFail</v>
        <v>Config = NewConfig = [{Key,Value}]</v>
        <v>CTHState = NewCTHState = term()</v>
        <v>Result = {NewConfig | SkipOrFail, NewCTHState}</v>
        <v>SkipOrFail = {fail,Reason} | {skip, Reason}</v>
        <v>Key = atom()</v>
        <v>Value = term()</v>
        <v>Reason = term()</v>
      </type>
      <desc>	
        <p>OPTIONAL</p>

        <p>This function is called before
          <seealso marker="common_test#Module:init_per_group-2"><c>init_per_group</c></seealso>
          if it exists. It behaves the same way as
          <seealso marker="ct_hooks#Module:pre_init_per_suite-3"><c>pre_init_per_suite</c></seealso>,
          but for function
          <seealso marker="common_test#Module:init_per_group-2"><c>init_per_group</c></seealso>
          instead.</p>

	<p>If <c>Module:pre_init_per_group/4</c> is not exported, common_test
	  will attempt to call <c>Module:pre_init_per_group(GroupName,
	  InitData, CTHState)</c> instead. This is for backwards
	  compatibility.</p>
      </desc>
    </func>

    <func>
      <name since="OTP 19.3">Module:post_init_per_group(SuiteName, GroupName, Config, Return, CTHState) -&gt; Result</name>
      <fsummary>Called after init_per_group.</fsummary>
      <type>
        <v>SuiteName = atom()</v>
        <v>GroupName = atom()</v>
        <v>Config = [{Key,Value}]</v>
        <v>Return = NewReturn = Config | SkipOrFail | term()</v>
        <v>SkipOrFail = {fail,Reason} | {skip, Reason}</v>
        <v>CTHState = NewCTHState = term()</v>
        <v>Result = {NewReturn, NewCTHState}</v>
        <v>Key = atom()</v>
        <v>Value = term()</v>
        <v>Reason = term()</v>
      </type>
      <desc>	
        <p>OPTIONAL</p>

        <p>This function is called after
          <seealso marker="common_test#Module:init_per_group-2"><c>init_per_group</c></seealso>
          if it exists. It behaves the same way as
          <seealso marker="ct_hooks#Module:post_init_per_suite-4"><c>post_init_per_suite</c></seealso>,
          but for function
          <seealso marker="common_test#Module:init_per_group-2"><c>init_per_group</c></seealso>
          instead.</p>

	<p>If <c>Module:post_init_per_group/5</c> is not exported, common_test
	  will attempt to call <c>Module:post_init_per_group(GroupName,
	  Config, Return, CTHState)</c> instead. This is for backwards
	  compatibility.</p>
      </desc>
    </func>

    <func>
      <name since="OTP 19.3">Module:pre_init_per_testcase(SuiteName, TestcaseName, InitData, CTHState) -&gt; Result</name>
      <fsummary>Called before init_per_testcase.</fsummary>
      <type>
        <v>SuiteName = atom()</v>
        <v>TestcaseName = atom()</v>
        <v>InitData = Config | SkipOrFail</v>
        <v>Config = NewConfig = [{Key,Value}]</v>
        <v>CTHState = NewCTHState = term()</v>
        <v>Result = {NewConfig | SkipOrFail, NewCTHState}</v>
        <v>SkipOrFail = {fail,Reason} | {skip, Reason}</v>
        <v>Key = atom()</v>
        <v>Value = term()</v>
        <v>Reason = term()</v>
      </type>
      <desc>	
        <p>OPTIONAL</p>

        <p>This function is called before
          <seealso marker="common_test#Module:init_per_testcase-2"><c>init_per_testcase</c></seealso>
          if it exists. It behaves the same way as
          <seealso marker="ct_hooks#Module:pre_init_per_suite-3"><c>pre_init_per_suite</c></seealso>,
          but for function
          <seealso marker="common_test#Module:init_per_testcase-2"><c>init_per_testcase</c></seealso>
          instead.</p>

	<p>If <c>Module:pre_init_per_testcase/4</c> is not exported, common_test
	  will attempt to call <c>Module:pre_init_per_testcase(TestcaseName,
	  InitData, CTHState)</c> instead. This is for backwards
	  compatibility.</p>

        <p>CTHs cannot be added here right now. That feature may be added in
          a later release, but it would right now break backwards
          compatibility.</p>
      </desc>
    </func>

    <func>
      <name since="OTP 19.3">Module:post_init_per_testcase(SuiteName, TestcaseName, Config, Return, CTHState) -&gt; Result</name>
      <fsummary>Called after init_per_testcase.</fsummary>
      <type>
        <v>SuiteName = atom()</v>
        <v>TestcaseName = atom()</v>
        <v>Config = [{Key,Value}]</v>
        <v>Return = NewReturn = Config | SkipOrFail | term()</v>
        <v>SkipOrFail = {fail,Reason} | {skip, Reason}</v>
        <v>CTHState = NewCTHState = term()</v>
        <v>Result = {NewReturn, NewCTHState}</v>
        <v>Key = atom()</v>
        <v>Value = term()</v>
        <v>Reason = term()</v>
      </type>
      <desc>	
        <p>OPTIONAL</p>

        <p>This function is called after
          <seealso marker="common_test#Module:init_per_testcase-2"><c>init_per_testcase</c></seealso>
          if it exists. It behaves the same way as
          <seealso marker="ct_hooks#Module:post_init_per_suite-4"><c>post_init_per_suite</c></seealso>,
          but for function
          <seealso marker="common_test#Module:init_per_testcase-2"><c>init_per_testcase</c></seealso>
          instead.</p>

	<p>If <c>Module:post_init_per_testcase/5</c> is not exported, common_test
	  will attempt to call <c>Module:post_init_per_testcase(TestcaseName,
	  Config, Return, CTHState)</c> instead. This is for backwards
	  compatibility.</p>
      </desc>
    </func>

    <func>
      <name since="OTP 19.3">Module:pre_end_per_testcase(SuiteName, TestcaseName, EndData, CTHState) -&gt; Result</name>
      <fsummary>Called before end_per_testcase.</fsummary>
      <type>
        <v>SuiteName = atom()</v>
        <v>TestcaseName = atom()</v>
        <v>EndData = Config</v>
        <v>Config = NewConfig = [{Key,Value}]</v>
        <v>CTHState = NewCTHState = term()</v>
        <v>Result = {NewConfig, NewCTHState}</v>
        <v>Key = atom()</v>
        <v>Value = term()</v>
        <v>Reason = term()</v>
      </type>
      <desc>	
        <p>OPTIONAL</p>

        <p>This function is called before
          <seealso marker="common_test#Module:end_per_testcase-2"><c>end_per_testcase</c></seealso>
          if it exists. It behaves the same way as
          <seealso marker="ct_hooks#Module:pre_end_per_suite-3"><c>pre_end_per_suite</c></seealso>,
          but for function
          <seealso marker="common_test#Module:end_per_testcase-2"><c>end_per_testcase</c></seealso>
          instead.</p>

        <p>This function can not change the result of the test case by returning skip or fail
	tuples, but it may insert items in <c>Config</c> that can be read in
	<c>end_per_testcase/2</c> or in <c>post_end_per_testcase/5</c>.</p>

	<p>If <c>Module:pre_end_per_testcase/4</c> is not exported, common_test
	  will attempt to call <c>Module:pre_end_per_testcase(TestcaseName,
	  EndData, CTHState)</c> instead. This is for backwards
	  compatibility.</p>
      </desc>
    </func>

    <func>
      <name since="OTP 19.3">Module:post_end_per_testcase(SuiteName, TestcaseName, Config, Return, CTHState) -&gt; Result</name>
      <fsummary>Called after end_per_testcase.</fsummary>
      <type>
        <v>SuiteName = atom()</v>
        <v>TestcaseName = atom()</v>
        <v>Config = [{Key,Value}]</v>
        <v>Return = NewReturn = Config | SkipOrFail | term()</v>
        <v>SkipOrFail = {fail,Reason} | {skip, Reason}</v>
        <v>CTHState = NewCTHState = term()</v>
        <v>Result = {NewReturn, NewCTHState}</v>
        <v>Key = atom()</v>
        <v>Value = term()</v>
        <v>Reason = term()</v>
      </type>
      <desc>	
        <p>OPTIONAL</p>

        <p>This function is called after
          <seealso marker="common_test#Module:end_per_testcase-2"><c>end_per_testcase</c></seealso>
          if it exists. It behaves the same way as
          <seealso marker="ct_hooks#Module:post_end_per_suite-4"><c>post_end_per_suite</c></seealso>,
          but for function
          <seealso marker="common_test#Module:end_per_testcase-2"><c>end_per_testcase</c></seealso>
          instead.</p>

	<p>If <c>Module:post_end_per_testcase/5</c> is not exported, common_test
	  will attempt to call <c>Module:post_end_per_testcase(TestcaseName,
	  Config, Return, CTHState)</c> instead. This is for backwards
	  compatibility.</p>
      </desc>
    </func>

    <func>
      <name since="OTP 19.3">Module:pre_end_per_group(SuiteName, GroupName, EndData, CTHState) -&gt; Result</name>
      <fsummary>Called before end_per_group.</fsummary>
      <type>
        <v>SuiteName = atom()</v>
        <v>GroupName = atom()</v>
        <v>EndData = Config | SkipOrFail</v>
        <v>Config = NewConfig = [{Key,Value}]</v>
        <v>CTHState = NewCTHState = term()</v>
        <v>Result = {NewConfig | SkipOrFail, NewCTHState}</v>
        <v>SkipOrFail = {fail,Reason} | {skip, Reason}</v>
        <v>Key = atom()</v>
        <v>Value = term()</v>
        <v>Reason = term()</v>
      </type>
      <desc>	
        <p>OPTIONAL</p>

        <p>This function is called before
          <seealso marker="common_test#Module:end_per_group-2"><c>end_per_group</c></seealso>
          if it exists. It behaves the same way as
          <seealso marker="ct_hooks#Module:pre_init_per_suite-3"><c>pre_init_per_suite</c></seealso>,
          but for function
          <seealso marker="common_test#Module:end_per_group-2"><c>end_per_group</c></seealso>
          instead.</p>

	<p>If <c>Module:pre_end_per_group/4</c> is not exported, common_test
	  will attempt to call <c>Module:pre_end_per_group(GroupName,
	  EndData, CTHState)</c> instead. This is for backwards
	  compatibility.</p>
      </desc>
    </func>

    <func>
      <name since="OTP 19.3">Module:post_end_per_group(SuiteName, GroupName, Config, Return, CTHState) -&gt; Result</name>
      <fsummary>Called after end_per_group.</fsummary>
      <type>
        <v>SuiteName = atom()</v>
        <v>GroupName = atom()</v>
        <v>Config = [{Key,Value}]</v>
        <v>Return = NewReturn = Config | SkipOrFail | term()</v>
        <v>SkipOrFail = {fail,Reason} | {skip, Reason}</v>
        <v>CTHState = NewCTHState = term()</v>
        <v>Result = {NewReturn, NewCTHState}</v>
        <v>Key = atom()</v>
        <v>Value = term()</v>
        <v>Reason = term()</v>
      </type>
      <desc>	
        <p>OPTIONAL</p>

        <p>This function is called after
          <seealso marker="common_test#Module:end_per_group-2"><c>end_per_group</c></seealso>
          if it exists. It behaves the same way as
          <seealso marker="ct_hooks#Module:post_init_per_suite-4"><c>post_init_per_suite</c></seealso>,
          but for function
          <seealso marker="common_test#Module:end_per_group-2">end_per_group</seealso>
          instead.</p>

	<p>If <c>Module:post_end_per_group/5</c> is not exported, common_test
	  will attempt to call <c>Module:post_end_per_group(GroupName,
	  Config, Return, CTHState)</c> instead. This is for backwards
	  compatibility.</p>
      </desc>
    </func>

    <func>
      <name since="OTP R14B02">Module:pre_end_per_suite(SuiteName, EndData, CTHState) -&gt; Result</name>
      <fsummary>Called before end_per_suite.</fsummary>
      <type>
        <v>SuiteName = atom()</v>
        <v>EndData = Config | SkipOrFail</v>
        <v>Config = NewConfig = [{Key,Value}]</v>
        <v>CTHState = NewCTHState = term()</v>
        <v>Result = {NewConfig | SkipOrFail, NewCTHState}</v>
        <v>SkipOrFail = {fail,Reason} | {skip, Reason}</v>
        <v>Key = atom()</v>
        <v>Value = term()</v>
        <v>Reason = term()</v>
      </type>
      <desc>	
        <p>OPTIONAL</p>

        <p>This function is called before
          <seealso marker="common_test#Module:end_per_suite-1"><c>end_per_suite</c></seealso>
          if it exists. It behaves the same way as
          <seealso marker="ct_hooks#Module:pre_init_per_suite-3"><c>pre_init_per_suite</c></seealso>,
          but for function
          <seealso marker="common_test#Module:end_per_suite-1"><c>end_per_suite</c></seealso>
          instead.</p>
      </desc>
    </func>

    <func>
      <name since="OTP R14B02">Module:post_end_per_suite(SuiteName, Config, Return, CTHState) -&gt; Result</name>
      <fsummary>Called after end_per_suite.</fsummary>
      <type>
        <v>SuiteName = atom()</v>
        <v>Config = [{Key,Value}]</v>
        <v>Return = NewReturn = Config | SkipOrFail | term()</v>
        <v>SkipOrFail = {fail,Reason} | {skip, Reason}</v>
        <v>CTHState = NewCTHState = term()</v>
        <v>Result = {NewReturn, NewCTHState}</v>
        <v>Key = atom()</v>
        <v>Value = term()</v>
        <v>Reason = term()</v>
      </type>
      <desc>	
        <p>OPTIONAL</p>

        <p>This function is called after
          <seealso marker="common_test#Module:end_per_suite-1"><c>end_per_suite</c></seealso>
          if it exists. It behaves the same way as
          <seealso marker="ct_hooks#Module:post_init_per_suite-4"><c>post_init_per_suite</c></seealso>,
          but for function
          <seealso marker="common_test#Module:end_per_suite-1"><c>end_per_suite</c></seealso>
          instead.</p>
      </desc>
    </func>

    <func>
      <name since="OTP 19.3">Module:on_tc_fail(SuiteName, TestName, Reason, CTHState) -&gt; NewCTHState</name>
      <fsummary>Called after the CTH scope ends.</fsummary>
      <type>
        <v>SuiteName = atom()</v>
        <v>TestName = init_per_suite | end_per_suite | {init_per_group,GroupName} | {end_per_group,GroupName} | {FuncName,GroupName} | FuncName</v>
        <v>FuncName = atom()</v>
        <v>GroupName = atom()</v>
        <v>Reason = term()</v>
        <v>CTHState = NewCTHState = term()</v>
      </type>
      <desc>	
        <p>OPTIONAL</p>

        <p>This function is called whenever a test case (or configuration
          function) fails. It is called after the post function is called
          for the failed test case, that is:</p>

        <list type="bulleted">
          <item><p>If <c>init_per_suite</c> fails, this function is called after
            <seealso marker="#Module:post_init_per_suite-4"><c>post_init_per_suite</c></seealso>.</p></item>
          <item><p>If a test case fails, this funcion is called after
          <seealso marker="#Module:post_end_per_testcase-5"><c>post_end_per_testcase</c></seealso>.</p></item>
        </list>

         <p>If the failed test case belongs to a test case group, the first
          argument is a tuple <c>{FuncName,GroupName}</c>, otherwise only
          the function name.</p>

        <p>The data that comes with <c>Reason</c> follows the same format as
          <seealso marker="event_handler_chapter#failreason"><c>FailReason</c></seealso>
          in event
          <seealso marker="event_handler_chapter#tc_done"><c>tc_done</c></seealso>.
          For details, see section
          <seealso marker="event_handler_chapter#events">Event Handling</seealso>
          in the User's Guide.</p>

	<p>If <c>Module:on_tc_fail/4</c> is not exported, common_test
	  will attempt to call <c>Module:on_tc_fail(TestName, Reason,
	  CTHState)</c> instead. This is for backwards
	  compatibility.</p>
      </desc>
    </func>

    <func>
      <name since="OTP 19.3">Module:on_tc_skip(SuiteName, TestName, Reason, CTHState) -&gt; NewCTHState</name>
      <fsummary>Called after the CTH scope ends.</fsummary>
      <type>
        <v>SuiteName = atom()</v>
        <v>TestName = init_per_suite | end_per_suite | {init_per_group,GroupName} | {end_per_group,GroupName} | {FuncName,GroupName} | FuncName</v>
        <v>FuncName = atom()</v>
        <v>GroupName = atom()</v>
        <v>Reason = {tc_auto_skip | tc_user_skip, term()}</v>
        <v>CTHState = NewCTHState = term()</v>
      </type>
      <desc>	
        <p>OPTIONAL</p>

        <p>This function is called whenever a test case (or configuration
          function) is skipped. It is called after the post function is called
          for the skipped test case, that is:</p>

        <list type="bulleted">
          <item><p>If <c>init_per_group</c> is skipped, this function is
            called after 
            <seealso marker="#Module:post_init_per_group-5"><c>post_init_per_group</c></seealso>.</p></item>
          <item><p>If a test case is skipped, this function is called after
          <seealso marker="#Module:post_end_per_testcase-5"><c>post_end_per_testcase</c></seealso>.</p></item>
        </list>

        <p>If the skipped test case belongs to a test case group, the first
          argument is a tuple <c>{FuncName,GroupName}</c>, otherwise only
          the function name.</p>

        <p>The data that comes with <c>Reason</c> follows the same format as
          events
          <seealso marker="event_handler_chapter#tc_auto_skip"><c>tc_auto_skip</c></seealso>
          and
          <seealso marker="event_handler_chapter#tc_user_skip"><c>tc_user_skip</c></seealso>
          For details, see section
          <seealso marker="event_handler_chapter#events">Event Handling</seealso>
          in the User's Guide.</p>

	<p>If <c>Module:on_tc_skip/4</c> is not exported, common_test
	  will attempt to call <c>Module:on_tc_skip(TestName, Reason,
	  CTHState)</c> instead. This is for backwards
	  compatibility.</p>
      </desc>
    </func>

    <func>
      <name since="OTP R14B02">Module:terminate(CTHState)</name>
      <fsummary>Called after the CTH scope ends.</fsummary>
      <type>
        <v>CTHState = term()</v>
      </type>
      <desc>	
        <p>OPTIONAL</p>

        <p>This function is called at the end of a CTH
          <seealso marker="ct_hooks_chapter#scope">scope</seealso>.</p>
      </desc>
    </func>

    <func>
      <name since="OTP R14B02">Module:id(Opts) -&gt; Id</name>
      <fsummary>Called before the init function of a CTH.</fsummary>
      <type>
        <v>Opts = term()</v>
        <v>Id = term()</v>
      </type>
      <desc>
       <p>OPTIONAL</p>
	
       <p>The <c>Id</c> identifies a CTH instance uniquely. If two CTHs return
         the same <c>Id</c>, the second CTH is ignored and subsequent calls to
         the CTH are only made to the first instance. For details, see section
         <seealso marker="ct_hooks_chapter#installing">Installing a CTH</seealso>
         in the User's Guide.</p>

       <p>This function is <em>not</em> to have any side effects, as it can 
         be called multiple times by <c>Common Test</c>.</p>

       <p>If not implemented, the CTH acts as if this function returned a call
         to <c>make_ref/0</c>.</p>
       </desc>
    </func>
  </funcs>

</erlref>