• Stars
    star
    14
  • Rank 1,438,076 (Top 29 %)
  • Language
    Perl
  • License
    Other
  • Created over 10 years ago
  • Updated about 4 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Build Status

NAME

Test::Kantan - simple, flexible, fun "Testing framework"

SYNOPSIS

use Test::Kantan;

describe 'String', sub {
  describe 'index', sub {
    it 'should return -1 when the value is not matched', sub {
      expect(index("abc", 'x'))->to_be(-1);
      expect(index("abc", 'a'))->to_be(0);
    };
  };
};

done_testing;

DESCRIPTION

Test::Kantan is a behavior-driven development framework for testing Perl 5 code. It has a clean, obvious syntax so that you can easily write tests.

CURRENT STATUS

Unstable. I will change the API without notice.

Interfaces

There is 3 types for describing test cases.

BDD style

RSpec/Jasmine like BDD style function names are available.

describe 'String', sub {
  before_each { ... };
  describe 'index', sub {
    it 'should return -1 when the value is not matched', sub {
      expect(index("abc", 'x'))->to_be(-1);
      expect(index("abc", 'a'))->to_be(0);
    };
  };
};

done_testing;

Given-When-Then style

There is the Given-When-Then style functions. It's really useful for describing real complex problems.

Scenario 'String', sub {
  setup { ... };

  Feature 'Get the index from the code', sub {
    Given 'the string';
    my $str = 'abc';

    When 'get the index for "a"';
    my $i = index($str, 'a');

    Then 'the return value is 0';
    expect($i)->to_be(0);
  };
};

done_testing;

Plain old Test::More style

subtest 'String', sub {
  setup { ... };

  subtest 'index', sub {
    expect(index("abc", 'x'))->to_be(-1);
    expect(index("abc", 'a'))->to_be(0);
  };
};

done_testing;

Assertions

Here is 2 type assertions.

ok()

ok { 1 };

There is the ok function. It takes one code block. The code returns true value if the test case was passed, false otherwise.

ok() returns the value what returned by the code.

expect()

expect($x)->to_be_true;

Here is the expect function like RSpec/Jasmine. For more details, please look Test::Kantan::Expect.

Utility functions

diag($message)

You can show the diagnostic message with diag() function. Diagnostic message would not print if whole test cases in the subtest were passed.

It means, you can call diag() without worries about the messages is a obstacle.

ignore()

The same as Test::Deep::NoTest's one. See also "ignore()" in Test::Deep

spy_on()

The same as "spy_on()" in Module::Spy

skip_all()

Skips all of the tests that are in the hereafter.

Hooks

setup()

setup { do_something() };

setup blocks are run before each example setup blocks are run once before all of the examples in a group.

teardown()

teardown { do_something() };

teardown blocks are run after each example teardown blocks are run once after all of the examples in a group.

before_each()

Alias of setup().

after_each

Alias of teardown().

ENVIRONMENT VARIABLES

  • KANTAN_REPORTER

    You can specify the reporter class by KANTAN_REPORTER environment variable.

      KANTAN_REPORTER=TAP perl -Ilib t/01_simple.t
    
  • KANTAN_CUTOFF

    Kantan cut the diagnostic message by 80 bytes by default. If you want to change this value, you can set by KANTAN_CUTOFF.

      KANTAN_CUTOFF=10000 perl -Ilib t/01_simple.t
    

Tips

How do I suppress output from Log::Minimal?

Log::Minimal outputs logs to STDERR by default.

$Log::Minimal::PRINT = sub {
    my ( $time, $type, $message, $trace,$raw_message) = @_;
    local $Test::Kantan::Level = $Test::Kantan::Level + 3;
    Test::Kantan::diag("$time [$type] $message at $trace", 1024);
};

How do I use the testing library based on Test::Builder?

Test::Kantan replace some methods in Test::Builder. You can use the library based on Test::Builder with Test::Kantan :)

LICENSE

Copyright (C) Tokuhiro Matsuno.

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

AUTHOR

Tokuhiro Matsuno [email protected]

moznion

Kuniwak

More Repositories

1

plenv

Perl binary manager
Shell
500
star
2

Amon

yet another web application framework
Perl
160
star
3

java-handbook

137
star
4

git-xlsx-textconv

Go
132
star
5

akaza

Yet another Japanese IME for IBus/Linux
Rust
127
star
6

Furl

pretty fast http client library for perl5
Perl
103
star
7

Minilla

Authorizing tool for CPAN modules
Perl
97
star
8

Perl-Build

Perl
79
star
9

spring-vue-sample

Java
71
star
10

p6-Crust

PSGI library stack for Perl6
Raku
66
star
11

node-perl

Node perl wrapper
C++
63
star
12

toydi

Java
63
star
13

cpan-outdated

detect outdated CPAN modules
Perl
52
star
14

tora

Tora! Tora! Tora!
Perl
51
star
15

avans

Tiny thin web application framework for Java 8
Java
50
star
16

js-xlsx-demo

JavaScript
50
star
17

SQL-Maker

Perl
47
star
18

jawiki-kana-kanji-dict

Generate SKK/MeCab dictionary from Wikipedia(Japanese edition)
Python
40
star
19

node-mruby

C++
40
star
20

Daiku

Yet another build tool on Perl5
Perl
38
star
21

teng-handbook

Perl
38
star
22

mobirc

IRC Gateway for MobilePhone/iPhone/PC
JavaScript
33
star
23

Test-TCP

Test::TCP for perl
Perl
33
star
24

jsref

JavaScript
33
star
25

re2c-lemon-tutorial

C++
32
star
26

p5-router-simple

simple http router
Perl
32
star
27

tinyorm

Tiny O/R mapper for Java
Java
29
star
28

p5-psgiref

(DEPRECATED)just a prototype!
Perl
28
star
29

Web-Query

Perl
27
star
30

OrePAN

Perl
26
star
31

obsidian-2hop-links-plugin

TypeScript
26
star
32

optimize-perl-doc

how to optimize your perl code?
Perl
26
star
33

frepan

freshness mirror of cpan viewer
JavaScript
25
star
34

strftime-js

JavaScript
25
star
35

menta

General extlib/ for CGI applications.
Perl
25
star
36

PJP

Perl
24
star
37

micro_dispatcher.js

JavaScript
22
star
38

data-model-tutorial

the tutorial documents for Data::Model
Perl
22
star
39

OrePAN2

Perl
22
star
40

hoshipad

JavaScript
22
star
41

FormValidator-Lite

very lite and fast validation library for perl
Perl
21
star
42

go-examples

my Golang examples repo.
Go
21
star
43

THWebViewController

Minimalistic WebViewController
Objective-C
20
star
44

go-hsperfdata

Quite fast jps/jstat
Go
20
star
45

Test-Pretty

Perl
20
star
46

p5-http-server-fast

(DEPRECATED)
C++
18
star
47

p6-HTTP-Server-Tiny

Web application server for Perl6
Perl 6
18
star
48

gearman-stat.psgi

Display gearman stats.
18
star
49

visualwidth-js

JavaScript
18
star
50

Router-Boom

Perl
18
star
51

obsidian-pomodoro-plugin

TypeScript
17
star
52

Archer

Perl
17
star
53

nanobench

Tiny benchmarking framework for Java 7+
Java
17
star
54

nanowww

C++ lightweight, fast, portable HTTP client library
Perl
17
star
55

mouse

Moose minus the antlers
Perl
16
star
56

www-mobilecarrierjp

WWW::MobileCarrierJP
Perl
16
star
57

http-session

http session management library for perl
Perl
16
star
58

HTML-TreeBuilder-LibXML

drop-in-replacement for HTML::TreeBuilder::XPath
Perl
16
star
59

Tiffany

Template-For-All, Generic interface for perl template engines.
Perl
16
star
60

DBIx-Inspector

Perl
16
star
61

w3m

my private repo of w3m
C
15
star
62

File-Zglob

Perl
15
star
63

madeye

simple infrastructure monitoring tool
Perl
15
star
64

Smart-Args

the new args.pm!
Perl
15
star
65

Caroline

Yet another line editing library for Perl5
Perl
14
star
66

p5-net-drizzle

libdrizzle bindings for perl5
C
14
star
67

perl-echo-servers

C
14
star
68

gearman-starter.pl

bootstrap script for gearman worker
Perl
13
star
69

MySQL-BinLog

Perl
13
star
70

obsidian-stopwatch-plugin

TypeScript
13
star
71

MetaCPANExplorer

CSS
13
star
72

node-tcc

C++
13
star
73

HTML-Pictogram-MobileJp

[emoji:1] ใฟใŸใ„ใชใฎใ‚’ๅ‡ฆ็†ใงใใ‚‹ไบบ
Perl
13
star
74

App-watcher

Perl
13
star
75

tinyvalidator

Tiny validation library for Java 8
Java
13
star
76

Text-Markdown-Hoedown

Perl
13
star
77

java-samples

Java
12
star
78

nanotap

yet another tap header library
HTML
12
star
79

App-scan_prereqs_cpanfile

Scan prerequisite modules and generate CPANfile
Perl
12
star
80

MojaMoja

(PoC)yet another sinatra-ish framework built on CPAN modules
Perl
12
star
81

Test-SharedFork

Test::SharedFork
Perl
12
star
82

p5-cgi-emulate-psgi

CGI::Emulate::PSGI
Perl
11
star
83

p5-anyevent-mprpc

MessagePack RPC component for AnyEvent!
Perl
11
star
84

mRuby.pm

Perl
11
star
85

devel-bindpp

Devel::BindPP makes writing perl extension easily
C++
11
star
86

Test-Power

Perl
11
star
87

regexp-trie

Regexp::Trie for Java7
Java
11
star
88

Sub-Retry

Perl
11
star
89

blosxom.psgi

cho45 style blosxom thing for psgi. see http://coderepos.org/share/wiki/BlosxomClones
10
star
90

cgi-extlib-perl

General extlib/ for Perl CGI applications.
Perl
10
star
91

p5-module-install-forc

M::I extension for standalone C program/library
Perl
10
star
92

DBIx-Kohada

Perl
10
star
93

Amon2-Lite

Perl
10
star
94

autolink.js

JavaScript
10
star
95

Module-Spy

Perl
10
star
96

p6-WebSocket

Perl 6
10
star
97

Harriet

Perl
10
star
98

Cache-KyotoTycoon

KyotoTycoon client library for Perl5
Perl
10
star
99

mindcheese

Editable mindmap library written in TypeScript
TypeScript
10
star
100

Perl-Lexer

C
10
star