Class Test

java.lang.Object
com.aventstack.chaintest.domain.Test
All Implemented Interfaces:
ChainTestEntity

public class Test extends Object implements ChainTestEntity
Represents a test in the ChainTest framework. This class contains information about the test such as its name, description, class name, start and end times, result, tags, error details, and child tests. It also provides methods to complete the test and update its statistics.
  • Constructor Details

    • Test

      public Test()
      Default constructor.
    • Test

      public Test(long buildId, String name, Optional<String> testClass, Collection<String> tags)
      Constructs a Test with the specified build ID, name, optional class name, and tags.
      Parameters:
      buildId - the build ID
      name - the name of the test
      testClass - the optional class name of the test
      tags - the tags associated with the test
    • Test

      public Test(long buildId, String name, Optional<String> testClass, Stream<String> tags)
      Constructs a Test with the specified build ID, name, optional class name, and tags.
      Parameters:
      buildId - the build ID
      name - the name of the test
      testClass - the optional class name of the test
      tags - the tags associated with the test
    • Test

      public Test(String name, Optional<String> testClass, Collection<String> tags)
      Constructs a Test with the specified name, optional class name, and tags.
      Parameters:
      name - the name of the test
      testClass - the optional class name of the test
      tags - the tags associated with the test
    • Test

      public Test(String name, Optional<String> testClass, Stream<String> tags)
      Constructs a Test with the specified name, optional class name, and tags.
      Parameters:
      name - the name of the test
      testClass - the optional class name of the test
      tags - the tags associated with the test
    • Test

      public Test(long buildId, String name, Optional<String> testClass)
      Constructs a Test with the specified build ID, name, and optional class name.
      Parameters:
      buildId - the build ID
      name - the name of the test
      testClass - the optional class name of the test
    • Test

      public Test(String name, Optional<String> testClass)
      Constructs a Test with the specified name and optional class name.
      Parameters:
      name - the name of the test
      testClass - the optional class name of the test
    • Test

      public Test(long buildId, String name, Collection<String> tags)
      Constructs a Test with the specified build ID, name, and tags.
      Parameters:
      buildId - the build ID
      name - the name of the test
      tags - the tags associated with the test
    • Test

      public Test(long buildId, String name, Stream<String> tags)
      Constructs a Test with the specified build ID, name, and tags.
      Parameters:
      buildId - the build ID
      name - the name of the test
      tags - the tags associated with the test
    • Test

      public Test(String name, Collection<String> tags)
      Constructs a Test with the specified name and tags.
      Parameters:
      name - the name of the test
      tags - the tags associated with the test
    • Test

      public Test(String name, Stream<String> tags)
      Constructs a Test with the specified name and tags.
      Parameters:
      name - the name of the test
      tags - the tags associated with the test
    • Test

      public Test(long buildId, String name)
      Constructs a Test with the specified build ID and name.
      Parameters:
      buildId - the build ID
      name - the name of the test
    • Test

      public Test(String name)
      Constructs a Test with the specified name.
      Parameters:
      name - the name of the test
    • Test

      public Test(long buildId, Method method, Collection<String> tags)
      Constructs a Test with the specified build ID, method, and tags.
      Parameters:
      buildId - the build ID
      method - the method representing the test
      tags - the tags associated with the test
    • Test

      public Test(Method method, Collection<String> tags)
      Constructs a Test with the specified method and tags.
      Parameters:
      method - the method representing the test
      tags - the tags associated with the test
    • Test

      public Test(long buildId, Method method)
      Constructs a Test with the specified build ID and method.
      Parameters:
      buildId - the build ID
      method - the method representing the test
    • Test

      public Test(Method method)
      Constructs a Test with the specified method.
      Parameters:
      method - the method representing the test
  • Method Details

    • complete

      public void complete()
      Completes the test with the current result.
    • complete

      public void complete(Optional<Throwable> error)
      Completes the test with the specified error.
      Parameters:
      error - the optional error that occurred during the test
    • complete

      public void complete(Throwable error)
      Completes the test with the specified error.
      Parameters:
      error - the error that occurred during the test
    • setEndedAt

      public void setEndedAt(Long endedAt)
    • getDurationPretty

      public String getDurationPretty()
      Returns the duration of the test in a human-readable format.
      Returns:
      the duration of the test as a pretty string
    • addTags

      public void addTags(Collection<String> tags)
    • addTag

      public void addTag(String tag)
    • addTag

      public void addTag(Tag tag)
    • addChild

      public void addChild(Test child)
    • addLog

      public void addLog(String log)
      Adds a log entry to the test.
      Parameters:
      log - the log entry to add
    • setIsBdd

      public void setIsBdd(boolean isBDD)
      Sets whether the test is a BDD (Behavior-Driven Development) test.
      Parameters:
      isBDD - true if the test is a BDD test, false otherwise
    • addEmbed

      public void addEmbed(String base64, String mediaType)
      Adds an embedded media to the test.
      Parameters:
      base64 - the base64-encoded media
      mediaType - the media type
    • addEmbed

      public void addEmbed(File file, String mediaType)
      Adds an embedded media to the test from a file.
      Parameters:
      file - the file containing the media
      mediaType - the media type
    • addEmbed

      public void addEmbed(byte[] bytes, String mediaType)
      Adds an embedded media to the test from a byte array.
      Parameters:
      bytes - the byte array containing the media
      mediaType - the media type
    • addEmbed

      public void addEmbed(Embed embed)
      Adds an embedded media to the test.
      Parameters:
      embed - the embedded media to add