Skip to content

Latest commit

 

History

History
 
 

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 

readme.md

Allure-java-diff-utils

This library provides advanced data logging to allure when using java-diff-utils

Wiki

https://java-diff-utils.github.io/java-diff-utils/

Usage

Add dependency:

<dependency>
    <groupId>io.qameta.allure</groupId>
    <artifactId>allure-java-diff-utils</artifactId>
    <version>LATEST</version>
    <scope>test</scope>
</dependency>

The library does not provide any ready-to-use assertions, but it does provide a method for generating an attachment to analyze the difference between left and right strings.

    new AllureDiff().diff("my first line\nmy second line", "my first line");

Then an attachment will be generated in the Allure report to display the difference in the two lines. Attachment example here

Examples

The library reveals itself to the maximum when comparing large structured data, such as json, csv or xml.

Json compare example:

new AllureDiff().diff(
        """
        {
          "id": 123,
          "name": "John Doe",
          "email": "john.doe@example.com",
          "isActive": true,
          "roles": [
            "admin",
            "user"
          ],
          "address": {
            "street": "123 Main St",
            "city": "New York",
            "zipcode": "10001"
          }
        }
        """ ,
        """
        {
          "id": 123,
          "name": "John Doe",
          "email": "john.doe@example.com",
          "isActive": true,
          "roles": [
            "admin",
            "user"
          ],
          "address": {
            "city": "New York",
            "zipcode": "10001",
            "additional": "test"
          }
        }
        """
);

Attachment example here

Xml compare example:

new AllureDiff().diff(
        """
        <?xml version="1.0" encoding="UTF-8"?>
        <user id="123">
            <name>John Doe</name>
            <email>john.doe@example.com</email>
            <isActive>true</isActive>
            <roles>
                <role>admin</role>
                <role>user</role>
            </roles>
            <address>
                <street>123 Main St</street>
                <city>New York</city>
                <zipcode>10001</zipcode>
            </address>
        </user>
        """,
        """
        <?xml version="1.0" encoding="UTF-8"?>
        <user id="123">
            <name>John Doe</name>
            <email>john.doe@example.com</email>
            <isActive>true</isActive>
            <roles>
                <role>admin</role>
                <role>user</role>
            </roles>
            <address>
                <city>New York</city>
                <zipcode>10001</zipcode>
                <additional>test</additional>
            </address>
        </user>
        """
);

Attachment example here

Assert

The library does not provide any assertions, but it does provide a Patch object that contains a diff that is available to any assertions needed.

    final Patch<String> patch = new AllureDiff().diff("my first line\nmy second line", "my first line");
    assertThat(patch.getDeltas()).isEmpty();