CleverFilter: A Tool to Filter and Sort CSV Data for Regression Testing

Define test scope precisely

Do you need to adjust your automated tests frequently because of new features? With CleverFilter, after not relevant ccode changes for the test scope of your automated test your regression tests will always remain green, even with large functional expansions.

CleverFilter allows you to filter JSON and CSV data to precisely define the test scope.

 

The data generated during testing is often in a different order. For example, because HashMap or HashSet were used. Without sorting, random snapshots with data in a different order are created again and again, which cannot be compared with each other. You can easily define sorting criteria to ensure your data is always in the same order, allowing you to develop robust regression tests you can trust.

package org.expectedbits.examples.csv;

import java.io.IOException;
import java.io.InputStream;
import org.expectedbits.support.junit5.Snapshot;
import org.junit.jupiter.api.Test;

/**
 * This example shows how you can assert the responce of the REST service
 */
public class RestServiceSensorStatisticsExampleTest {

  /**
   * Retrieve sensor statistics from REST service. The statistics numbers are very precise and
   * changes on the 15-17 decimal place. Thus you need to round them to make snapshot content
   * reproducible.
   */
  @Test
  void restServiceResponseToSnapshot() throws IOException {

    try (InputStream is = retrieveCsvSensorStatisticsFromRestService()) {
      Snapshot.csvSnapshot(is)

          //filter statistics only for Sep 2022
          .filterRows(row -> row.getValue("Date").startsWith("2022-09"))

          //sort rows to ensure order
          .sortRows("Date")

          //round to 12 decimal places
          .roundNumbers(1E-12, "AVG_OVERLAY_ERROR_[X|Y]")

          //compare with expected values
          .assertToFile();
    }
  }
}

Leave a Comment

GDPR Cookie Consent with Real Cookie Banner