-
Notifications
You must be signed in to change notification settings - Fork 0
/
MANUAL
786 lines (529 loc) · 27.5 KB
/
MANUAL
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
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
Erlunit 0.2.8.2/alpha - MANUAL
----------------------------------------------------------------------------o--
---ooo-ooo--o--o--o-o--o-o-ooo----------------------------------------------o--
---Oo--OoO--O--O--O-Oo-O-O--O-----------------------------------------------o--
---Ooo-O--O-Ooo-oo--O-oO-O--O-----------------------------------------------o--
----------------------------------------------------------------------------o--
Copyright (c) 2010 Eonblast Corporation http://www.eonblast.com
== Index ==
Start Up
* Very Quick Start: quick.erl
* Quick Start
* Download & Installation
* Samples: sample.erl
* Quick Check
* Support
* Home
Reference
* Tests
* Suites
* Checks
* Macros
* All Checks and Macros
Theory
* Why would you use this?
* Why would you not use this?
* Links
* MIT License
----------------------------------------------------------------------------o--
---ooo-ooo--o--o--o-o--o-o-ooo----------------------------------------------o--
---Oo--OoO--O--O--O-Oo-O-O--O-----------------------------------------------o--
---Ooo-O--O-Ooo-oo--O-oO-O--O-----------------------------------------------o--
----------------------------------------------------------------------------o--
== Very Quick Start: quick.erl ==
* Get Erlunit from http://github.com/hdiedrich/erlunit/tarball/master
* Extract, go into that dir and do:
$ erl
1> c(erlunit), c(quick), quick:run().
This is what you'll see:
-------------------------------------------------------------------------o--
erlunit: Start of Tests.
Eshell V5.7.2 (abort with ^G)
1> erlunit: + ok | Equality check | 1 == 1 as it should.
erlunit: ------------------------------------------------------------------
erlunit: + OK | Default Suite: all 1 tests passed.
erlunit: ------------------------------------------------------------------
erlunit: oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo
erlunit: All passed - Tests: 1, Passed: 1, Failed: 0, Crashes: 0
erlunit: oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo
-------------------------------------------------------------------------o--
* Take a look at quick.erl:
----------------------------------------------------------------------------o--
-module(quick).
-import(erlunit).
-export([run/0]).
run() ->
erlunit:start(),
erlunit:equal(1, 1),
erlunit:execute().
----------------------------------------------------------------------------o--
* Take a look at sample.erl
It is written to be read top down, tutorial style. And you can run() it.
----------------------------------------------------------------------------o--
---ooo-ooo--o--o--o-o--o-o-ooo----------------------------------------------o--
---Oo--OoO--O--O--O-Oo-O-O--O-----------------------------------------------o--
---Ooo-O--O-Ooo-oo--O-oO-O--O-----------------------------------------------o--
----------------------------------------------------------------------------o--
== On Tests ==
"I do use a form of micro testing that is built into Erlang." - Joe Armstrong
Joe Armstrong describes how you don't really need a test frame work in many
situations, because the pattern matching in Erlang can be used for testing:
http://armstrongonsoftware.blogspot.com/2009/01/micro-lightweight-unit-testing.html
If you'd still like to use something a tad more baroque, yet simple, this
package here may be a start. Best, start reading the beginning of sample.erl
and try those samples:
$ erl
1> c(erlunit), c(sample), sample:sample1().
2> c(erlunit), c(sample), sample:sample2().
3> ...
Tests are written to test functions of your own source. There is a
a lot to be said for writing tests for your source and even write
test before you write your source: to clarify and define your task
and to make life easier once you change implementations.
Fom the source at http://www.c2.com/cgi/wiki?TestDrivenDevelopment:
"
* Think about what you want to do.
* Think about how to test it.
* Write a small test. Think about the desired API.
* Write just enough code to fail the test.
* Run and watch the test fail. (The test-runner, if you're using something like
JUnit, shows the "Red Bar"). Now you know that your test is going to be executed.
* Write just enough code to pass the test (and pass all your previous tests).
* Run and watch all of the tests pass. (The test-runner, if you're using JUnit,
etc., shows the "Green Bar"). If it doesn't pass, you did something wrong,
fix it now since it's got to be something you just wrote.
* If you have any duplicate logic, or inexpressive code, refactor to remove
duplication and increase expressiveness -- this includes reducing coupling
and increasing cohesion.
* Run the tests again, you should still have the Green Bar. If you get the Red
Bar, then you made a mistake in your refactoring. Fix it now and re-run.
* Repeat the steps above until you can't find any more tests that drive writing
new code.
Note that your code comes into play where 1 is used in this first
sample. Eg. to test your function Foo() that is expected to always
result into 42 when fed with a bar, you'd write a test like this:
equal(Foo(bar), 42). This way you have a test coded that will make
sure that Foo(bar) still results into 42, whenever you run it, no
matter how many source iterations later you come back to it."
=== Alternate notation ===
Erlunit allows for sequential, and message passing notation:
sample1() ->
erlunit:start(),
erlunit:equal(1, 1),
...
erlunit:execute().
sample2() ->
Test = erlunit:start(),
Test ! { equal, 1, 1 },
...
Test ! execute.
=== Suites ===
'Suites' are used to group individual tests.
A suite is created with erlunit:suite("<suite name>"). Tests are
grouped into the suite last created, by default.
sample3() ->
erlunit:start(),
erlunit:suite("#1"),
erlunit:equal(100, 100),
...
erlunit:suite("#2"),
erlunit:not_equal(a, b),
...
erlunit:execute().
----------------------------------------------------------------------------o--
---ooo-ooo--o--o--o-o--o-o-ooo----------------------------------------------o--
---Oo--OoO--O--O--O-Oo-O-O--O-----------------------------------------------o--
---Ooo-O--O-Ooo-oo--O-oO-O--O-----------------------------------------------o--
----------------------------------------------------------------------------o--
== Quick Start ==
You should be making your first real tests for your own project within 5 min.
{1} Copy erlunit.erl into your path (for now).
{2} Create a test file test.erl and paste into:
-import(your_module_to_be_tested.erl)
-import(erlunit.erl)
run() ->
erlunit:start(),
erlunit:true(yourFunToBeTested(ATestValue) == TheExpectedResult),
erlunit:execute().
{3} Compile & Run it:
# erl
1> c(your_module_to_be_tested), c(erlunit), c(test), test:run().
Done.
=== Message Passing Notation ===
There is a message passing notation that allows for concurrent tests:
Test = erlunit:start(),
Test ! { true, yourFun(ATestValue) == TheExpectedResult },
Test ! execute.
=== Other Checks ===
This first test uses true(). Other checks are: false, equal, bigger, lesser, pass,
fail, throws, error, exits.
In more detail:
* erlunit:true(A) resp.: { true, A }
* erlunit:false(A) { false, A }
* erlunit:equal(A, B) { equal, A, B }
* erlunit:bigger(A, B) ...
* erlunit:lesser(A, B)
* erlunit:pass(Fun)
* erlunit:fail(Fun)
* erlunit:throws(Fun)
* erlunit:error(Fun)
* erlunit:exits(Fun)
They can all take an optional description text as last parameter:
* erlunit:true(A, Descr) resp.: { true, A, Descr }
* erlunit:false(A, Descr) { false, A, Descr }
* erlunit:equal(A, B, Descr) { equal, A, B, Descr }
* ... ...
You can use suites and run them concurrently. That works like this:
test3() ->
erlunit:start(),
erlunit:suite("#1"),
erlunit:equal(100, 100),
% ...
erlunit:suite("#2"),
erlunit:not_equal(a, b),
% ...
erlunit:execute().
Or, alternately, the Suite process takes the place of Test from above:
test3() ->
erlunit:start(),
Suite1 = erlunit:suite("#1"),
Suite1 ! { true, 1 == 1 },
% ...
Suite2 = erlunit:suite("#2"),
Suite2 ! { not_equal, 1, 2 },
% ...
erlunit:execute().
See sample.erl for more samples. See 'Checks' for a complete list of checks.
----------------------------------------------------------------------------o--
---ooo-ooo--o--o--o-o--o-o-ooo----------------------------------------------o--
---Oo--OoO--O--O--O-Oo-O-O--O-----------------------------------------------o--
---Ooo-O--O-Ooo-oo--O-oO-O--O-----------------------------------------------o--
----------------------------------------------------------------------------o--
== Support ==
Mail to hd2010@eonblast.com with questions and suggestions, I will be happy
to answer. - Henning
----------------------------------------------------------------------------o--
---ooo-ooo--o--o--o-o--o-o-ooo----------------------------------------------o--
---Oo--OoO--O--O--O-Oo-O-O--O-----------------------------------------------o--
---Ooo-O--O-Ooo-oo--O-oO-O--O-----------------------------------------------o--
----------------------------------------------------------------------------o--
== Home ==
http://wiki.github.com/Eonblast/Erlunit/
Note that this is not the 'Erlunit' that some web pages mentioned prior to 2010.
----------------------------------------------------------------------------o--
---ooo-ooo--o--o--o-o--o-o-ooo----------------------------------------------o--
---Oo--OoO--O--O--O-Oo-O-O--O-----------------------------------------------o--
---Ooo-O--O-Ooo-oo--O-oO-O--O-----------------------------------------------o--
----------------------------------------------------------------------------o--
== Download & Install ==
TAR: http://github.com/Eonblast/Erlunit/tarball/master
Bounces you to latest tarball. E.g.: Eonblast-Erlunit-94148e3.tar.gz
ZIP: http://github.com/Eonblast/Erlunit/zipball/master
Bounces you to latest zip. E.g.: Eonblast-Erlunit-94148e3.zip
GIT: git clone git://github.com/Eonblast/Erlunit.git erlunit
All you need is erlunit.erl:
a) Just copy erlunit.erl into your path.
That can be right into your main directory for starters.
- or -
b) Put the whole tar/zip contents into a subdirectory erlunit/:
(<GITTAG> == e.g. 94148e3)
$ mv Eonblast-Erlunit-<GITTAG>.tar.gz my_project_folder
$ cd my_project_folder
$ tar xvzf Eonblast-Erlunit-<GITTAG>.tar.gz
$ mv Eonblast-Erlunit-<GITTAG> erlunit
Now the Erlunit files are in my_project_folder/erlunit. Test it:
$ cd my_project_folder/erlunit
$ erl
1> c(erlunit), c(test), test:run().
- or -
c) Pull from git
$ git clone git://github.com/Eonblast/Erlunit.git erlunit
----------------------------------------------------------------------------o--
---ooo-ooo--o--o--o-o--o-o-ooo----------------------------------------------o--
---Oo--OoO--O--O--O-Oo-O-O--O-----------------------------------------------o--
---Ooo-O--O-Ooo-oo--O-oO-O--O-----------------------------------------------o--
----------------------------------------------------------------------------o--
== Samples: sample.erl ==
erlunit:start(), % initializes & prints heads
erlunit:true(1 == 1,"1 and 1 are equal"), % stages tests
...
erlunit:execute(). % executes & prints results
That's it. Read more in sample.erl.
Using Suites:
erlunit:start(), % initializes & prints heads
erlunit:suite("Suite 1"), % initialize a suite
erlunit:true(1 == 1,"1 and 1 are equal"), % mounts tests
...
erlunit:execute(). % executes & prints results
Suites are used for organizing tests that belong together. More in sample.erl.
----------------------------------------------------------------------------o--
---ooo-ooo--o--o--o-o--o-o-ooo----------------------------------------------o--
---Oo--OoO--O--O--O-Oo-O-O--O-----------------------------------------------o--
---Ooo-O--O-Ooo-oo--O-oO-O--O-----------------------------------------------o--
----------------------------------------------------------------------------o--
== Quick Check ==
For a quick check, run, in the folder where Erlunit resides, do
$ erl
1> c(erlunit), c(quick), quick:run().
A lot more samples are in sample.erl: 1> c(erlunit), c(sample), sample:run().
They can be run one at a time: 2> sample:sample1(). ...
To test Erlunit itself: {ok,_} = c(erlunit), {ok,_} = c(testtest), testtest:run().
These other files can be executed and inspected:
> c(erlunit), c(quick), quick:run().
> c(erlunit), c(template), template:run().
> c(erlunit), c(sample), sample:sample1().
----------------------------------------------------------------------------o--
---ooo-ooo--o--o--o-o--o-o-ooo----------------------------------------------o--
---Oo--OoO--O--O--O-Oo-O-O--O-----------------------------------------------o--
---Ooo-O--O-Ooo-oo--O-oO-O--O-----------------------------------------------o--
----------------------------------------------------------------------------o--
== Tests ==
Tests are written to test functions of your own source. There is a
a lot to be said for writing tests for your source and even write
test before you write your source: to clarify and define your task
and to make life easier once you change implementations.
See http://www.c2.com/cgi/wiki?TestDrivenDevelopment for more.
Note that your code comes into play where 1 is used in this first
sample. Eg. to test your function Foo() that is expected to always
result into 42 when fed with a bar, you'd write a test like this:
equal(Foo(bar), 42). This way you have a test coded that will make
sure that Foo(bar) still results into 42, whenever you run it, no
matter how many source iterations later you come back to it.
Imperative - or - Message Passing
------------------------- ------------------------
erlunit:start(), Test = erlunit:start(),
erlunit:true(A), Test ! { true, A },
erlunit:execute(). Test ! execute.
== Suites ==
'Suites' are used to group individual tests.
A suite is created with erlunit:suite("<suite name>"). Tests are
grouped into the suite last created, by default.
Imperative - or - Message Passing
------------------------- ------------------------
erlunit:start(), Test = erlunit:start(),
erlunit:suite("SuiteName"), Suite = erlunit:suite("SuiteName"),
erlunit:true(A, B), Suite ! { true, yourFun(ATestValue) == TheExpectedResult },
erlunit:execute(). Test ! execute.
Suites can be run concurrently. Running those samples will show how the
individual checks of both suits are neatly interleaving. This only works
with the message passing notation. It exploits the effect
that the suites are 'loaded' with checks pretty fast and the actual
execution of the checks doesn't start before erlunit:execute() is called.
Which in effect mostly means: wait for the suites to get done. And so it
waits and gives the suites the chance to use the cpu time between them.
== Checks ==
Checks are called:
Imperative - or - Message Passing
------------------------- ------------------------
erlunit:<name>([<suite>, ] <param> [,<Descr>]) [<test or suite>] ! { <name>, <param> [, Descr] }
- or -
Imperative Macros
-------------------------
?ERLUNIT_<name>([<suite>, ] <param> [,<Descr>])
[ ] here is to mean 'optional', not 'Erlang list'.
<name> is one of:
true, false, equal, bigger, lesser
pass, fail, throws, error, exits
not_true, not_false, not_equal
<suite> is a suite process, created by suite().
<test or suite> are either a test process or a suite process, which are
returned by start() and suite() respectively.
<param> are your parameters to the check. The actual meat to it all.
<Descr> is your description string to recognize the individual check
in the test log, especially in case it fails.
<test or suite> are either a test process or a suite process, which are
returned by start() and suite() respectively.
== Macros ==
Macros add a stringified text of: A, module and code line for the output.
For example ?ERLUNIT_TRUE(a == a) is translated into something like:
erlunit:true(fun() -> a == a end, "a == a", "sample.erl", 510 )).
Macros MUST NOT get a Fun as argument, they wrap every expression A into a
Fun themselves. Where a check like erlunit:pass() needs a Fun as argument,
Macros gets only the inner expression A of a Fun fun() -> A end.
Include erlunit.hrl in your source to use macros. They are defined like so:
-define(ERLUNIT_TRUE(A), erlunit:true(fun() -> A end, ??A, ?MODULE, ?LINE )).
== All Checks and Macros ==
The complete list of checks:
Imperative - or - Message Passing
------------------------- ------------------------
erlunit:true(A) Test ! { true, A }
erlunit:false(A) Test ! { false, A }
erlunit:equal(A, B) Test ! { equal, A, B }
erlunit:bigger(A, B) Test ! { bigger, A, B }
erlunit:lesser(A, B) Test ! { lesser, A, B }
erlunit:pass(Fun) Test ! { pass, Fun }
erlunit:fail(Fun) Test ! { fail, Fun }
erlunit:throws(Fun) Test ! { throws, Fun }
erlunit:error(Fun) Test ! { error, Fun }
erlunit:exits(Fun) Test ! { exits, Fun }
erlunit:not_true(A) Test ! { not_true, A }
erlunit:not_false(A) Test ! { not_false, A }
erlunit:not_equal(A, B) Test ! { not_equal, A, B }
Macros MUST NOT get a Fun, they wrap every expression A into a Fun themselves.
They are using the inner expression A of a Fun (fun() -> A end) of above:
Include erlunit.hrl to use macros. They are defined like this:
-define(ERLUNIT_TRUE(A), erlunit:true(fun() -> A end, ??A, ?MODULE, ?LINE )).
This adds a stringified text of: A, module and code line for the output.
Imperative Macros
-------------------------
?ERLUNIT_TRUE(A)
?ERLUNIT_FALSE(A)
?ERLUNIT_EQUAL(A, B)
?ERLUNIT_BIGGER(A, B)
?ERLUNIT_LESSER(A, B)
?ERLUNIT_PASS(A) % A, not Fun
?ERLUNIT_FAIL(A) %
?ERLUNIT_THROWS(A) %
?ERLUNIT_ERROR(A) %
?ERLUNIT_EXITS(A) %
?ERLUNIT_NOT_TRUE(A)
?ERLUNIT_NOT_FALSE(A)
?ERLUNIT_NOT_EQUAL(A, B)
They can all take an optional description text as last parameter:
Imperative - or - Message Passing
------------------------- ------------------------
erlunit:true(A) Test ! { true, A }
erlunit:false(A) Test ! { false, A }
erlunit:equal(A, B) Test ! { equal, A, B }
erlunit:bigger(A, B) Test ! { bigger, A, B }
erlunit:lesser(A, B) Test ! { lesser, A, B }
erlunit:pass(Fun) Test ! { pass, Fun }
erlunit:fail(Fun) Test ! { fail, Fun }
erlunit:throws(Fun) Test ! { throws, Fun }
erlunit:error(Fun) Test ! { error, Fun }
erlunit:exits(Fun) Test ! { exits, Fun }
erlunit:not_true(A) Test ! { not_true, A }
erlunit:not_false(A) Test ! { not_false, A }
erlunit:not_equal(A, B) Test ! { not_equal, A, B }
Macros add _MSG:
Imperative Macros
-------------------------
?ERLUNIT_TRUE_MSG(A, MSG)
?ERLUNIT_FALSE_MSG(A, MSG)
?ERLUNIT_EQUAL_MSG(A, B, MSG)
?ERLUNIT_BIGGER_MSG(A, B, MSG)
?ERLUNIT_LESSER_MSG(A, B, MSG)
?ERLUNIT_PASS_MSG(A, MSG)
?ERLUNIT_FAIL_MSG(A, MSG)
?ERLUNIT_THROWS_MSG(A, MSG)
?ERLUNIT_ERROR_MSG(A, MSG)
?ERLUNIT_EXITS_MSG(A, MSG)
?ERLUNIT_NOT_TRUE_MSG(A, MSG)
?ERLUNIT_NOT_FALSE_MSG(A, MSG)
?ERLUNIT_NOT_EQUAL_MSG(A, B, MSG)
All checks accept a Suite that they belong to, as shown below. This
can be combined with the description above. If no Suite is specified, the
check is sorted into the last created suite. If no suite was created, they
are automatically in an internal default suite.
Imperative - or - Message Passing
------------------------- ------------------------
erlunit:true(Suite, A) Suite ! { true, A }
erlunit:false(Suite, A) Suite ! { false, A }
erlunit:equal(Suite, A, B) Suite ! { equal, A, B }
erlunit:bigger(Suite, A, B) Suite ! { bigger, A, B }
erlunit:lesser(Suite, A, B) Suite ! { lesser, A, B }
erlunit:pass(Suite, Fun) Suite ! { pass, Fun }
erlunit:fail(Suite, Fun) Suite ! { fail, Fun }
erlunit:throws(Suite, Fun) Suite ! { throws, Fun }
erlunit:error(Suite, Fun) Suite ! { error, Fun }
erlunit:exits(Suite, Fun) Suite ! { exits, Fun }
erlunit:not_true(Suite, A) Suite ! { not_true, A }
erlunit:not_false(Suite, A) Suite ! { not_false, A }
erlunit:not_equal(Suite, A, B) Suite ! { not_equal, A, B }
----------------------------------------------------------------------------o--
---ooo-ooo--o--o--o-o--o-o-ooo----------------------------------------------o--
---Oo--OoO--O--O--O-Oo-O-O--O-----------------------------------------------o--
---Ooo-O--O-Ooo-oo--O-oO-O--O-----------------------------------------------o--
----------------------------------------------------------------------------o--
== Why would you use this? ==
You could be making your first real tests for your own project in 5 min.
{1}
Copy erlunit.erl into your path
{2}
Create a test file test.erl and paste into:
-import(your_module_to_be_tested.erl)
-import(erlunit.erl)
run() ->
erlunit:start(),
erlunit:true(yourFunToBeTested(ATestValue) == TheExpectedResult),
erlunit:execute().
{3}
Compile & Run it, done:
# erl
1> c(erlunit), c(test), test:run().
Done. Other checks are: false, equal, bigger, lesser, pass, fail, throws,
error, exits.
Continue reading above, 'Quick Start'.
----------------------------------------------------------------------------o--
---ooo-ooo--o--o--o-o--o-o-ooo----------------------------------------------o--
---Oo--OoO--O--O--O-Oo-O-O--O-----------------------------------------------o--
---Ooo-O--O-Ooo-oo--O-oO-O--O-----------------------------------------------o--
----------------------------------------------------------------------------o--
== Why would you not use this? ==
E r l u n i t is a naive approach at an academically covered issue.
Thus consider these two serious contenders who deserve your attention:
E U n i t - by Richard Carlsson and Michaêl Rémond:
"EUnit is a unit testing framework for Erlang. It is very powerful and
flexible, is easy to use, and has small syntactical overhead."
http://svn.process-one.net/contribs/trunk/eunit/doc/overview-summary.html
e t a p - by Jeremy Wall, Paul J. Davis, Nick Gerakines et al:
"etap is a collection of Erlang modules that provide a TAP testing client
library. These modules allow developers to create extensive and compre-
hensive tests covering many aspects of application and module development.
This includes simple assertions, exceptions, the application behavior and
event web requests." http://github.com/ngerakines/etap/downloads
----------------------------------------------------------------------------o--
---ooo-ooo--o--o--o-o--o-o-ooo----------------------------------------------o--
---Oo--OoO--O--O--O-Oo-O-O--O-----------------------------------------------o--
---Ooo-O--O-Ooo-oo--O-oO-O--O-----------------------------------------------o--
----------------------------------------------------------------------------o--
== Links ==
Test-driven Development
* Xtreme Programming: http://c2.com/cgi/wiki?TestDrivenDevelopment
* Dijkstra '88: http://www.cs.utexas.edu/users/EWD/ewd10xx/EWD1012.PDF
* Joe Armstrong: http://armstrongonsoftware.blogspot.com/2009/01/micro-lightweight-unit-testing.html
* http://en.wikipedia.org/wiki/Test-driven_development
Unit Testing
* http://en.wikipedia.org/wiki/Unit_testing
Erlang Unit Test Frameworks
* EUnit: http://svn.process-one.net/contribs/trunk/eunit/doc/overview-summary.html
* etap: http://github.com/ngerakines/etap/downloads
* Erlunit: http://github.com/Eonblast/Erlunit
----------------------------------------------------------------------------o--
---ooo-ooo--o--o--o-o--o-o-ooo----------------------------------------------o--
---Oo--OoO--O--O--O-Oo-O-O--O-----------------------------------------------o--
---Ooo-O--O-Ooo-oo--O-oO-O--O-----------------------------------------------o--
----------------------------------------------------------------------------o--
== License ==
Copyright (c) 2010 Eonblast Corporation http://www.eonblast.com
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice, including link, and this permission notice shall
be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
----------------------------------------------------------------------------o--
---ooo-ooo--o--o--o-o--o-o-ooo----------------------------------------------o--
---Oo--OoO--O--O--O-Oo-O-O--O-----------------------------------------------o--
---Ooo-O--O-Ooo-oo--O-oO-O--O-----------------------------------------------o--
----------------------------------------------------------------------------o--
File : MANUAL
Description : Description of Erlunit
Type : Documentation
Version : 0.2.8.2/alpha
Status : alpha
Copyright : (c) 2010 Eonblast Corporation http://www.eonblast.com
License : MIT - see above
Author : H. Diedrich <hd2010@eonblast.com>
Created : 24 Apr 2010
Changed : 29 Apr 2010 - also see CHANGES
----------------------------------------------------------------------------o--