aboutsummaryrefslogtreecommitdiffstats
path: root/lib/test_server/doc/src/example_chapter.xml
blob: 6bc0cfaebec0ede1fb36deafbf5eb2ee7993f97f (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
<?xml version="1.0" encoding="utf-8" ?>
<!DOCTYPE chapter SYSTEM "chapter.dtd">

<chapter>
  <header>
    <copyright>
      <year>2002</year><year>2013</year>
      <holder>Ericsson AB. All Rights Reserved.</holder>
    </copyright>
    <legalnotice>
      The contents of this file are subject to the Erlang Public License,
      Version 1.1, (the "License"); you may not use this file except in
      compliance with the License. You should have received a copy of the
      Erlang Public License along with this software. If not, it can be
      retrieved online at http://www.erlang.org/.
    
      Software distributed under the License is distributed on an "AS IS"
      basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
      the License for the specific language governing rights and limitations
      under the License.
    
    </legalnotice>

    <title>Examples</title>
    <prepared>Siri Hansen</prepared>
    <docno></docno>
    <date></date>
    <rev></rev>
    <file>example_chapter.xml</file>
  </header>

  <section>
    <title>Test suite</title>
    <code type="none">
-module(my_SUITE).

-export([all/1,
         not_started/1, not_started_func1/1, not_started_func2/1,
         start/1, stop/1,
         func1/1, func2/1 
        ]).

-export([init_per_testcase/2, end_per_testcase/2]).

-include("test_server.hrl").

-define(default_timeout, ?t:minutes(1)).

init_per_testcase(_Case, Config) ->
    Dog=?t:timetrap(?default_timeout),
    [{watchdog, Dog}|Config].
end_per_testcase(_Case, Config) ->
    Dog=?config(watchdog, Config),
    ?t:timetrap_cancel(Dog),
    ok.

all(suite) -> 
    %% Test specification on test suite level
    [not_started,
     {conf, start, [func1, func2], stop}].

not_started(suite) ->
    %% Test specification on test case level
    [not_started_func1, not_started_func2];
not_started(doc) ->
    ["Testing all functions when application is not started"].
%% No execution clause unless the specification clause returns [].


not_started_func1(suite) ->
    [];
not_started_func1(doc) ->
    ["Testing function 1 when application is not started"].
not_started_func1(Config) when list(Config) ->
    {error, not_started} = myapp:func1(dummy_ref,1),
    {error, not_started} = myapp:func1(dummy_ref,2),
    ok.

not_started_func2(suite) ->
    [];
not_started_func2(doc) ->
    ["Testing function 2 when application is not started"].
not_started_func2(Config) when list(Config) ->
    {error, not_started} = myapp:func2(dummy_ref,1),
    {error, not_started} = myapp:func2(dummy_ref,2),
    ok.


%% No specification clause needed for an init function in a conf case!!!
start(doc) ->
    ["Testing start of my application."];
start(Config) when list(Config) ->
    Ref = myapp:start(),
    case erlang:whereis(my_main_process) of
      Pid when pid(Pid) -> 
         [{myapp_ref,Ref}|Config];
      undefined -> 
         %% Since this is the init function in a conf case, the rest of the 
         %% cases in the conf case will be skipped if this case fails.
         ?t:fail("my_main_process did not start")
    end.

func1(suite) ->
    [];
func1(doc) ->
    ["Test that func1 returns ok when argument is 1 and error if argument is 2"];
func1(Config) when list(Config) ->
    Ref = ?config(myapp_ref,Config),
    ok = myapp:func1(Ref,1),
    error = myapp:func1(Ref,2),
    ok.

func2(suite) ->
    [];
func2(doc) ->
    ["Test that func1 returns ok when argument is 3 and error if argument is 4"];
func2(Config) when list(Config) ->
    Ref = ?config(myapp_ref,Config),
    ok = myapp:func2(Ref,3),
    error = myapp:func2(Ref,4),
    ok.

%% No specification clause needed for a cleanup function in a conf case!!!
stop(doc) ->
    ["Testing termination of my application"];
stop(Config) when list(Config) ->
    Ref = ?config(myapp_ref,Config),
    ok = myapp:stop(Ref),
    case erlang:whereis(my_main_process) of
      undefined -> 
         lists:keydelete(myapp_ref,1,Config);
      Pid when pid(Pid) -> 
         ?t:fail("my_main_process did not stop")
    end.
    </code>
  </section>

  <section>
    <title>Test specification file</title>
    <p><em><c>myapp.spec:</c></em></p>
    <code type="none">
{topcase, {dir, "../myapp_test"}}. % Test specification on top level    </code>
    <p><em><c>myapp.spec.vxworks:</c></em></p>
    <code type="none">
{topcase, {dir, "../myapp_test"}}. % Test specification on top level
{skip,{my_SUITE,func2,"Not applicable on VxWorks"}}.    </code>
  </section>
</chapter>