/usr/share/doc/libahven6-dev/tutorial/tutorial.html is in libahven6-dev 2.6-1.2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 | <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><title> Ahven Unit Test Library - Tutorial </title>
<style type="text/css">
body { background-color: white }
</style>
<!-- <link rel="stylesheet" type="text/css" href="ahven.css"/> -->
<!-- <meta http-equiv="Content-Type" content="text/html;charset=utf-8" /> -->
</head><body>
<h1>Ahven Tutorial</h1>
<p>Copyright (c) 2007, 2008 Tero Koskinen
<<a href="mailto:tero.koskinen@iki.fi">tero.koskinen@iki.fi</a>>
<p> Contents:
<ul>
<li> <a href="tutorial.html#introduction">Introduction</a> </li>
<li> <a href="tutorial.html#firsttest">First Test Case</a> </li>
<li> <a href="tutorial.html#running">Running a Test Case</a> </li>
</ul>
</p>
<h2><a name="introduction">Introduction</a></h2>
<p> Ahven is a unit test library modeled after JUnit library for Java.
So, for JUnit users the API should be familiar.
</p>
<p> The heart of the library is an abstract
class called <code>Test</code>. It has two subclasses,
<code>Test_Case</code>, and <code>Test_Suite</code>.
<code>Test_Case</code> is the base class for other unit tests
and <code>Test_Suite</code> is a container, which can hold
<code>Test</code> objects.
</p>
<p> <img src="ahven.png" title="Ahven.Framework" alt="Ahven.Framework class diagram" />
</p>
<h2><a name="firsttest">First Test Case</a></h2>
<p>For your first test case, you need to create a new package and a new
class, which is derived from Ahven.Framework.Test_Case.
Let's call the package <code>My_Tests</code> and the class
<code>My_Tests.Test</code>.
</p>
<p>
<code>
<pre>
-- my_tests.ads
with Ahven.Framework;
package My_Tests is
type Test is new Ahven.Framework.Test_Case with null record;
end My_Tests;
</pre>
</code>
</p>
<p> After you have defined your class, you need to overload
<code>Test_Case</code>'s <code>Initialize</code> procedure
and create your own test procedure (<code>My_First_Test</code>).
</p>
<p>
<code>
<pre>
-- my_tests.ads
with Ahven.Framework;
package My_Tests is
type Test is new Ahven.Framework.Test_Case with null record;
<b>procedure Initialize (T : in out Test);</b>
<b>procedure My_First_Test;</b>
end My_Tests;
</pre>
</code>
</p>
<p> Next you need to create the body of the My_Tests package.
In <code>Initialize</code> procedure you need to do two things:
<ul>
<li> Set a name for the test case,
<li> and register the test procedures.
</ul>
</p>
<p>
<code>
<pre>
-- my_tests.adb
package body My_Tests is
procedure Initialize (T : in out Test) is
begin
<b>Set_Name (T, "My tests");</b>
<b>Ahven.Framework.Add_Test_Routine
(T, My_First_Test'Access, "My first test");</b>
end Initialize;
...
end My_Tests;
</pre>
</code>
</p>
<p> In the test procedure <code>My_First_Test</code> you can do anything
you want. The Ahven package defines two utility procedures for you:
<code>Assert (Condition : Boolean; Message : String)</code>
and <code>Fail (Message : String)</code>.
</p>
<p> <code>Assert</code> will raise Assertion_Error if
<code>Condition</code> is <code>False</code>.
<code>Fail</code> does what its name implies and will raise
<code>Assertion_Error</code> always.
These <code>Assertion_Error</code>s will show as failures when you
run the tests.
</p>
<p> Here is an example: </p>
<p>
<code>
<pre>
-- my_tests.adb
<b>with Ahven;
use Ahven;</b>
package body My_Tests is
procedure Initialize (T : in out Test) is
begin
Set_Name (T, "My tests");
Framework.Add_Test_Routine
(T, My_First_Test'Access, "My first test");
end Initialize;
<b>
procedure My_First_Test is
begin
Assert (1 /= 4, "1 /= 4 failed!");
end My_First_Test;
</b>
end My_Tests;
</pre>
</code>
</p>
<h2><a name="running">Running a Test Case</a></h2>
<p> To run your tests you need to feed them to a test runner.
For example, <code>Ahven.Text_Runner.Run</code> runs the tests
and prints the results to the standard output.
</p>
<p> The best way to run the tests is to define a Test_Suite, add
the tests there, and give the test suite to the runner.
</p>
<p>
<code>
<pre>
-- runner.adb
with Ahven.Text_Runner;
with Ahven.Framework;
with My_Tests;
procedure Runner is
S : Ahven.Framework.Test_Suite_Access :=
Ahven.Framework.Create_Suite ("All my tests");
begin
Ahven.Framework.Add_Test (S.all, new My_Tests.Test);
Ahven.Text_Runner.Run (S);
Ahven.Framework.Release_Suite (S);
-- Release_Suite will release all its children also.
end Runner;
</pre>
</code>
</p>
<hr/>
<p>Tero Koskinen, 2008-01-07</p>
</body></html>
|