Code Monkey home page Code Monkey logo

microtest's Introduction

๐Ÿ”ฌ microtest Crystal CI

Version 1.2.7

A small testing framework inspired by minitest/minitest.cr.

Features

  • This framework is opinionated
  • It uses power asserts by default. There are no assert_equals, assert_xyz, just power asserts (except for assert_raises)
  • It uses the spec syntax for test case structure (describe, test, before, after). Reasons: No test-case name-clashes when using describe. Not forgetting to call super in setup/teardown methods.
  • No nesting of describe blocks. IMO nesting of those blocks is an anti-pattern.
  • No let-definitions. Only before / after hooks. Use local variables mostly.
  • Tests have to be started explicitly by Microtest.run!, no at-exit hook.
  • Colorized and abbreviated exception stacktraces
  • Randomized test order (SEED can be specified as environment variable)
  • Focus individual tests (test! "my test" do ...)
  • Different reportes (progress, descriptions, slow tests)

Installation

Add this to your application's shard.yml:

development_dependencies:
  microtest:
    github: ragmaanir/microtest
    version: ~> 1.2.7

And add this to your spec_helper.rb:

require "microtest"

include Microtest::DSL

Microtest.run!

Usage

class WaterPump
  getter name : String
  getter speed : Int32
  getter? enabled : Bool = false

  def initialize(@name, @speed = 10)
  end

  def enable
    @enabled = true
  end
end

describe WaterPump do
  test "enabling" do
    p = WaterPump.new("main")
    p.enable

    assert(p.enabled?)
  end

  test "pump speed" do
    p = WaterPump.new("main", speed: 100)

    assert(p.speed > 50)
  end

  test "this one is pending since it got no body"

  pending "this one is pending even though it has a body" do
    raise "should not raise"
  end
end

Run the test with:

crystal spec

You can provide the seed to run the tests in the same order:

SEED=123 crystal spec

Power Assert Output

describe AssertionFailure do
  test "assertion failure" do
    a = 5
    b = "aaaaaa"
    assert "a" * a == b
  end
end

Generates:

missing

Microtest Test Output (microtest tests using progress reporter)

missing

Reporters

Use common reporter combinations:

# both versions include error-list-, slow-tests- and summary-reporters:
Microtest.run!(:progress)
Microtest.run!(:descriptions)

Or select the used reporters explicitly:

Microtest.run!([
  Microtest::DescriptionReporter.new,
  Microtest::ErrorListReporter.new,
  Microtest::SlowTestsReporter.new,
  Microtest::SummaryReporter.new,
] of Microtest::Reporter)
describe First do
  test "success" do
  end

  test "skip this"
end

describe Second do
  def raise_an_error
    raise "Oh, this is wrong"
  end

  test "first failure" do
    a = 5
    b = 7
    assert a == b * 2
  end

  test "error" do
    raise_an_error
  end
end

Progress Reporter

missing

Description Reporter

missing

When focus active

describe Focus do
  test "not focused" do
  end

  test! "focused" do
  end

  test "focused too", :focus do
  end
end

missing

Development

Run ./cli readme to run tests and generate README.md from README.md.ecr and generate the images of the test outputs (using an alpine docker image).

microtest's People

Contributors

ragmaanir avatar veelenga avatar willamin avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

veelenga willamin

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.