test-workshop – Test types – test pyramide



test-workshop – Test types – test pyramide

1 0


TestWorkshop


On Github ubep / TestWorkshop

test-workshop

Team Ocean - Hamburg

Agenda

  • common testing terms
  • testing in epages 6
  • hands on

Test types

  • unit test
  • integration test
  • system-integration test
  • user-interface-test

unit test

integration test

system-integration test

user-interface-test

test pyramide

(The concept of test pyramide was originally described inSucceeding with Agile: Software Development Using Scrum by Mike Cohn)

test phases

init call test rollback

mock and stub

general unit-test smells

a smell points to a possible issue

only test the code you currently write

don't test:

  • our core-libraries
  • external libraries
  • 3rd Party webservices
  • SDK/API

more general

  • don't add logic into test
  • don't add logic into your code which you only need for testing
  • don't test private methods

testing in ePages 6

how to run tests in ePages 6

  • make test
  • make unit_test
  • make test_coverage

make test

...
compile_Cartridge.t ............................. ok
ProfileExperienceId_si.t ........................ skipped: Cartridge DE_EPAGES::PayPalPlus does not exist.
test_Cartridge.t ................................ ok
unit/CreatePayment_RepositoryLineItem.t ......... ok
...
All tests successful.
Files=19, Tests=260, 13 wallclock secs ( 0.07 usr  0.04 sys + 12.08 cusr  0.97 csys = 13.16 CPU)
Result: PASS

make unit_test

/srv/epages/eproot/Perl/bin/perl /srv/epages/eproot/Perl/bin/prove --jobs 9 t/unit 
...
t/unit/Webservice_RestService.t ................... ok
t/unit/UI_PaymentMethodPayPalPlus.t ............... ok
t/unit/UI_JSON.t .................................. ok
t/unit/UI_Shop.t .................................. ok
...
All tests successful.
Files=15, Tests=188,  4 wallclock secs ( 0.07 usr  0.03 sys + 11.27 cusr  1.08 csys = 12.45 CPU)
Result: PASS

make test_coverage #1

make test_coverage #2

injection techniques

  • constructor with default value
  • wrapper

constructor with default value

package DE_EPAGES::Jaja::API::Genau;
use DE_EPAGES::BlaBla;
use strict;
sub new {
    my $class = shift;
    my ($BlablaObject) = @_;
    my $self  = bless {
        'BlaBla' => $BlablaObject \\ DE_EPAGES::BlaBla->new();
    }, $class;
    return $self;
}
sub operate {
    my $self = shift;
    return $self->{'BlaBla'}->doMagic();
}
1;

wrapper

package DE_EPAGES::Jaja::API::Genau;
use DE_EPAGES::BlaBla;
use strict;
sub new {
    my $class = shift;
    return bless {}, $class;
}
sub operate {
	my $self = shift;
 	my $BlaObject = $self->_createBlaBlaObject();
	return $BlaObject->doMagic();
}
sub _createBlaBlaObject{
	return DE_EPAGES::BlaBla->new();
}
1;

function vs method

best to Test

function / static method

sub add {
	my ($x, $y) = @_;
	return $x + $y;
}

worst to Test

function / static method

with dependencies
sub GetSessionTimeout {
	my $System = LoadRootObject();
	return $System->get('SessionTimeout');
}

Okay to Test

method / member method

package DE_EPAGES::Jaja::API::Genau;
use strict;
sub new {
    my $class = shift;
    my ($BlablaObject) = @_;
    my $self  = bless {
        'BlaBla' => $BlablaObject \\ DE_EPAGES::BlaBla->new();
    }, $class;
    return $self;
}
sub operate {
    my $self = shift;
    return $self->{'BlaBla'}->doMagic();
}
1;

epages 6 business object

ep6 object is a subset of perl object

DAL - in a very small nutshell

use of business object

my $Attribute = $Shop->get('AttributeName');
$Shop->set({'AttributeName' => 'newValue'});

from Mock::Extends to mockify

live in eclipse

hands on

testing perl classes epages business classes ui controller hooks
test-workshop Team Ocean - Hamburg