Original presentation is Richard Carlsson's at Erlang Factory Bay Area 2009.
Erlangの世界的なイベントの中のEUnitの説明の資料です。分かりやすくEUnitの特徴がまとまっています。翻訳を許可してくれて、オリジナルの資料を送っていただいたRichardさんに感謝したいと思います。
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
EUnit in Practice(Japanese)
1. Eunit
Richard Carlsson
Kreditor Europe AB
(Translated by SHIBUKAWA Yoshiki)
qD `YZ [ = yoshiki@shibu.jp ]
2. Eunit / xUnit c
] [8QLW c 223 *
`a c` c c`
(UODQJ _ ` a
(XQLW IXQ (UODQJ [ c`a=
c c ^ ^
(XQLW 3 Z
3. c` a
.../myproject/
Makefile
src/
*.{erl,hrl}
ebin/
*.beam
4. ca .` a
# c Makefile
ERLC_FLAGS=
SOURCES=$(wildcard src/*.erl)
HEADERS=$(wildcard src/*.hrl)
OBJECTS=$(SOURCES:src/%.erl=ebin/%.beam)
all: $(OBJECTS) test
ebin/%.beam : src/%.erl $(HEADERS) Makefile
erlc $(ERLC_FLAGS) -o ebin/ $
clean:
-rm $(OBJECTS)
test:
erl -noshell -pa ebin
-eval 'eunit:test(ebin,[verbose])'
-s init stop
5. c` a c cb c
%% c= : src/global.hrl
-include_lib(eunit/include/eunit.hrl).
6. ` c
%% c= : src/empty.erl
-module(empty).
-include(global.hrl).
%% `a ^]
a_test() - ok.
7. c `a
$ make
erlc -o ebin/ src/empty.erl
erl -noshell -pa ebin
-eval 'eunit:test(ebin,[verbose])'
-s init stop
====================== EUnit ======================
directory ebin
empty:a_test (module 'empty')...ok
[done in 0.007 s]
===================================================
Test successful.
$
8. test _ `b a ^^
1 empty:module_info(exports).
[{a_test,0},{test,0},{module_info,0},
{module_info,1}]
2 empty:test().
Test passed.
ok
3 eunit:test(empty).
Test passed.
ok
4 empty:a_test().
ok
5 eunit:test({empty,a_test}).
Test passed.
ok
6
9. `a
ERLC_FLAGS=-DNOTEST makefile ^
= `a c ^ Z
# A simple Makefile
ERLC_FLAGS=-DNOTEST
...
`a a ca
^=” make release” ^ Z]
release: clean
$(MAKE) ERLC_FLAGS=$(ERLC_FLAGS) -DNOTEST
10. `a a c
$ make
erlc -DNOTEST -o ebin/ src/empty.erl
erl -noshell -pa ebin
-eval 'eunit:test(ebin,[verbose])'
-s init stop
====================== EUnit ======================
directory ebin
module 'empty'
[done in 0.004 s]
There were no tests to run.
$
11. `a Z Z [
1 empty:module_info(exports).
[{module_info,0},{module_info,1}]
2 eunit:test(empty).
There were no tests to run.
ok
3
12. _ca `a
c cb c NOTEST
c ^ = _ca `a
%% : src/global.hrl
-define(NOTEST, true).
-include_lib(eunit/include/eunit.hrl).
= TEST makefile ^
= NOTEST Z Z^
`a ^ makefile a
^ Z^
[=PZ ] Z[
13. `a aV
`a a [
eunit.hrl cc ` `Z
EUnit ` Z ^
c ^[ `a EUnit
= [ aZ ^
EUnit _ `b a 2 ]
EUnit Z Z a c
B = Z c Z Z ^
32. ZZZ ] Z
fib_tests:17: g_test_...ok
fib_tests:17: g_test_...ok
...
fib_tests:17: g_test_...[0.001 s] ok
fib_tests:17: g_test_...[0.002 s] ok
fib_tests:17: g_test_...[0.003 s] ok
fib_tests:17: g_test_...[0.005 s] ok
fib_tests:17: g_test_...[0.008 s] ok
fib_tests:17: g_test_...[0.013 s] ok
fib_tests:17: g_test_...[0.021 s] ok
...
fib_tests:17: g_test_...[0.566 s] ok
fib_tests:17: g_test_...[0.939 s] ok
[done in 3.148 s]
===================================================
All 40 tests passed.
33. `a Z
ZZZ^ ^ Z]
^ ^][
*= ZZ^ ` _ ]
a .( `c
c`a= ]c`a=a ]c`a
c [ `a ` Z Z
[ ^ [[ =
2 ^