Giter Club home page Giter Club logo

citron's Introduction

Citron

Simple testing framework. Provides fluent syntax for various assertions.

Build Status codecov

Dependency

This project is distributed via JitPack. Register a JitPack repository at your pom.xml:

<repositories>
    <repository>
        <id>jitpack.io</id>
        <url>https://jitpack.io</url>
    </repository>
</repositories>

And add the following dependency:

<dependency>
    <groupId>com.github.jolice</groupId>
    <artifactId>Citron</artifactId>
    <version>v1.0</version>
    <scope>test</scope>
</dependency>

Basic usage

All assertions begin with assertThat() followed by an application of the matchers.

int result = 2 + 2;
assertThat(result)
       .isNotNull()
       .and()
       .is(4)
       .and()
       .isIn(3, 4, 5);

Assertions are chained and separated by and() expression. All assertions are evaluated in the order they are specified in. It means that, for the specified example, result will be first checked for nulity, then whether it's equal to 4 and then whether it's in the [3, 4, 5] collection.

List of currently supported assertions:

Method name Parameter Asserts that
matches Predicate Actual Value matches a custom predicate
is Expected value Expected value equals actual value
isNot Expected value Expected value does not equal actual value
sameWith Expected value Expected and actual references point to the same instance
isNull - Actual value is null
isNotNull - Actual value is not null
isSubclassOf Type Class of the actual value is the subclass of the specified class
isInstanceOf Type Actual value is an instance of the specified class
isAnything - Always passes, regardless of the actual value
isIn Collection of elements Whether the collection contains actual value
isNotIn Collection of elements Whether the collection does not contain actual value
equalToEveryOf Collection of elements Whether the collection completely consists of actual values

Method assertions

Method assertions allow for asserting whether an execution of some method (or multiple methods) was completed without producing an exception.

For example, given the method:

public void fail() {
    throw new UnsupportedOperationException();
}

The following assertion will pass:

assertThat(this::fail)
        .doesThrow(UnsupportedOperationException.class);

To assert that method completes without throwing a runtime exception:

String result = "abcde";
assertThat(() -> result.substring(1))
         .completesNormally();

String assertions

There are some additional assertions for string provided, such as contains or whether string is equal to another one ignoring the case.

assertThat("abcde")
        .isNotNull()
        .and()
        .ignoringCase().is("AbCdE")
        .and()
        .contains("bcd");

Full list of assertion methods for the strings:

Method name Asserts that
matches String matches a regular expression
contains String contains another string
endsWith String ends with another string
startsWith String starts with another string
ignoringCase Equality ignoring the case
ignoringWhitespace Equality ignoring the whitespace

citron's People

Contributors

jolice avatar

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.