Kernel::Test::Role::IsTestCase::Generic::ComparesData

NAME

Kernel::Test::Role::IsTestCase::Generic::ComparesData – role to perform checks of test data.

PUBLIC INTERFACE

has 'DataDiffType'

holds the command-line attribute –data-diff-type to control the output for non-matching nested structures.

Success()

record a positive test result without comparing any data.

    $Self->Success( 'Test description' );

Failure()

record a negative test result without comparing any data.

    $Self->Failure( 'Test description' );

RequireParams()

Verify that specific keys exist in a given hashref. Fail the test, if it is not. Return boolean whether all required params where found.

Usage: return if ! $Self->RequireParams( \%Param, # that have been extracted from @_ earlier [ 'Some param name', 'Another param name'], );

True()

test for a scalar value that evaluates to true.

    my $Success = $Self->True( $Value, 'Test description' );

False()

has the same interface as "True()", but tests for a false value instead.

Is()

compares two scalar values for equality.

    my $Success = $Self->Is(
        $Value,             # test data
        1,                  # expected value
        'Test description',
    );

IsNot()

has the same interface as "Is()", but tests for inequality instead.

IsDeeply()

compares complex data structures for equality.

    my $Success = $Self->IsDeeply(
        \%ResultHash,           # test data
        \%ExpectedHash,         # expected value
        'Test description',     # meaningful description
        \@Exclude,              # optional list of elements to exclude
    );

IsNotDeeply()

has the same interface as "IsDeeply()", but tests for deep inequality instead.

MatchFieldsWildcard()

Compares $ActualData against the pattern \%ExpectedHash.

Only Fields in $ExpectedData are checked.

In Arrays only the values from $ExpectedData need to be in the $ActualData

On Scalar values the placeholder * can be used to accept any content.

    my $Success = $Self->IsDeeply(
        $ActualData,               # Reference to the actual data
        $ExpectedData,             # Reference to the expected values
        'Test description',        # meaningful description
        'Field Name',              # name of the structure
        1,                         # Fatal - stop on any error (default: 1)
        2,                         # Assertions - possible values (default: 2):
                                   #   0 - do not perform any assertions, only report the result
                                   #   1 - only perform the top level assertion and report the result
                                   #   2 - perform sub assertions and report the result
    );

MatchFieldsRegex()

Compares $ActualData against the pattern \%ExpectedHash.

Only Fields in $ExpectedData are checked.

In Arrays only the values from $ExpectedData need to be in the $ActualData

On Scalar values the defined regular expression is matched against the actual value.

    my $Success = $Self->IsDeeply(
        $ActualData,               # Reference to the actual data
        $ExpectedData,             # Reference to the expected values
        'Test description',        # meaningful description
        'Field Name',              # name of the structure
        1,                         # Fatal - stop on any error (default: 1)
        2,                         # Assertions - possible values (default: 2):
                                   #   0 - do not perform any assertions, only report the result
                                   #   1 - only perform the top level assertion and report the result
                                   #   2 - perform sub assertions and report the result
    );
Scroll to Top