Skip to content

YunaBraska/wiser-unit

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Wiser Unit

Build Maintainable Issues Commit Dependencies License Central Tag Javadoc Size Label

Description

BDD test methods and report generator

Features

  • Provides BDD methods [SUMMARY, FEATURE, GIVEN, THEN, WHEN, AND, BUT, WHERE, MATCH]
  • Provides BDD error message with preconditions
  • Provides a preview of the error line
  • Report generation in [JSON, YAML, HTML, CSV]
  • [...] your feature request?

Usage

<dependency>
    <groupId>berlin.yuna</groupId>
    <artifactId>wiser-unit</artifactId>
    <version>0.0.4</version>
</dependency>

Example Report

ReportExample

Configuration

  • Config wiser_report.yaml (can be placed at the root folder of the project):
name: "Custom report name"
generateYaml: true #generates yaml report
generateHtml: true #generates html report
generateCsv: true #generates csv report
generateJson: true #generates json report - cant be disabled as json is the base for other reports
generateNew: true #[false: update current report (parallel tests) / true: delete previous]
generateFlow: true #[will also generates flow for successful tests using regex]
errorPreviewLines: 1 #Class lines to preview when error occurred
outputDir: "%user.dir%/target/wiser-unit" #report output, folder
classesIgnore: "MyAnnoyingClassName" #Will ignore the class while scanning for error line/preview
testFileExtensions: "java, groovy" #Used for `errorPreviewLines` and `generateFlow` 

Get latest version

Usage report

  • @WiserJunitReport annotation adds the class test to the report generator
@Tag("UnitTest")
@WiserJunitReport
class MyTest {
    //....
}

Usage BDD methods

  • Basic example
.given("Input is my short phone number",10)
        .when(
        "Filter even numbers",
        number->LongStream.rangeClosed(1,number).boxed().filter(value->value%2==0).collect(toList())
        ).then(...)
  • Junit assertions
.then(
        "[Junit] Should contain five even numbers",
        value->{
        assertNotNull(value);
        assertEquals(5,value.size());
        return value;
        }
        )
.match(
        "[Junit] Should not be null",
        Assertions::assertNotNull
        )
.match(
        "[Junit] Should contain five even numbers",
        value->{
        assertNotNull(value);
        assertEquals(5,value.size());
        }
        );
.willThrow(RuntimeException.class,()->{
        throw new RuntimeException("expected");
        });
  • Hamcrest
.match(
        "[Hamcrest] Should contain five even numbers",
        is(notNullValue()),
        hasSize(5)
        );
.then(
        "[Hamcrest] Should contain five even numbers",
        value->{
        assertThat(value,is(notNullValue()));
        assertThat(value,hasSize(5));
        return value;
        });

Example failed test

berlin.yuna.wiserjunit.model.exception.BddException: 
✅ FEATURE: This is a test about an unknown feature
✅ GIVEN: Input is my short phone number
✅ WHEN : Filter even numbers
✅ MATCH: [Hamcrest] Should contain five even numbers
✅ THEN : [Hamcrest] Should contain five even numbers
✅ MATCH: [Junit] Should not be null
✅ MATCH: [Junit] Should contain five even numbers
✅ THEN : [Junit] Should contain five even numbers
❌ MATCH: Should throw [RuntimeException]
   [FAILED] with: Unexpected exception type thrown
        
    at berlin.yuna.wiserjunit.model.bdd.BddCore.renderException(BddCore.java:155)
[...]