Git Product home page Git Product logo

approvaltests.java's Introduction

Build Status Build Status Maven Central

Contents

ApprovalTests.Java

Capturing Human Intelligence - ApprovalTests is an open source assertion/verification library to aid unit testing.

It is compatible with JUnit 3, 4 & 5 and TestNG.

The jars can be used from JDK 1.8 on up until JDK 18.

What can it be used for?

Approval Tests can be used for verifying objects that require more than a simple assert. They also come prepackaged with utilities for some common java scenarios including

  • HashMaps & Collections
  • Long Strings
  • Log Files
  • JPanels
  • Xml
  • Html
  • Json
  • Getting Legacy Code under tests

Documentation

Getting started

The best way to get started is download and open one of the starter projects:

These are standard projects and can be imported into any editor or IDE.
They also all have CI with Github actions.

You might also want to check out the Getting Started Overview

How to get it

It's on Maven Central, search for 'approvaltests'.

Maven

If you're using Maven, add this to your pom file:

<dependency>
    <groupId>com.approvaltests</groupId>
    <artifactId>approvaltests</artifactId>
    <version>15.5.0</version>
</dependency>

Gradle

dependencies {
    testImplementation("com.approvaltests:approvaltests:15.5.0")
}

or download the jars from maven central repository

You can watch a bunch of short videos on getting started and using ApprovalTests in Java at youtube.

Note: There are a lot of videos about ApprovalTests in .Net They are equally useful for understanding the concepts despite being in a different programming language.

Podcasts

If you prefer auditory learning, you might enjoy the following podcast (Note: Some of these talk about the .net side)

Examples

ApprovalTests eats it own dogfood, so the best examples are in the source code itself.

None the less, Here's a quick look

public class SampleArrayTest
{
  @Test
  public void testList()
  {
    String[] names = {"Llewellyn", "James", "Dan", "Jason", "Katrina"};
    Arrays.sort(names);
    Approvals.verifyAll("", names);
  }
}

snippet source | anchor

Will Produce a File SampleArrayTest.testList.received.txt

[0] = Dan
[1] = James
[2] = Jason
[3] = Katrina
[4] = Llewellyn

snippet source | anchor

Simply rename this to SampleTest.testList.approved.txt and the test will now pass.

Approved File Artifacts

The *.approved.* files must be checked into source your source control. This can be an issue with git as it will change the line endings. The suggested fix is to add *.approved.* binary to your .gitattributes

More Info

No Checked Exceptions Philosophy

Approval Tests follows the no checked exceptions" philosophy. That is, our API only throws runtime exceptions.

LICENSE

Apache 2.0 License

Questions?

twitter: @LlewellynFalco or #ApprovalTests

Developer notes

The suggested way to contribute to ApprovalTests is to pair with Llewellyn
However, if you are set on forking please read these notes

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.