Loading ...
Sorry, an error occurred while loading the content.

Declarative testing (cont'd)

Expand Messages
  • Rob Nagler
    We have been using our bunit structure for about a week now. Here s our canonical example for Bivio::Math::EMA: # Copyright (c) 2005 bivio Software Artisans
    Message 1 of 1 , Sep 16 2:16 PM
    • 0 Attachment
      We have been using our bunit structure for about a week now. Here's
      our canonical example for Bivio::Math::EMA:

      # Copyright (c) 2005 bivio Software Artisans Inc. All Rights reserved.
      # $Id: EMA.bunit,v 1.2 2005/09/16 20:03:41 nagler Exp $
      [
      4 => [
      compute => [
      5 => 5,
      5 => 5,
      10 => 7,
      ],
      value => 7,
      ],
      class() => [
      new => [
      -2 => DIE(),
      0 => DIE(),
      1 => undef,
      2.5 => DIE(),
      ],
      ],
      50 => [
      value => DIE(),
      ],
      ];

      This was reduced from the more complex and imperative version:

      http://www.bivio.biz/f/bOP/tests/Bivio/Math/t/EMA.t

      And, the even more imperative Test::More version:

      http://www.extremeperl.org/bk/test-driven-design

      The latest bOP release changed the bunit structure to allow dynamic
      calls into a TestUnit type, e.g.,

      # Copyright (c) 2005 bivio Software, Inc. All Rights Reserved.
      # $Id: Acknowledgement.bunit,v 1.4 2005/09/16 20:03:41 nagler Exp $
      Request();
      [
      class() => [
      save_label => [
      ['abc', req()] => [],
      ],
      extract_label => [
      [req()] => ['abc'],
      ],
      ],
      sub {req()} => [
      unsafe_get_nested => [
      ['Action.Acknowledgement', 'label'] => ['abc'],
      ],
      ],
      class() => [
      extract_label => [
      [req()] => [undef],
      ],
      ],
      sub {req()} => [
      unsafe_get => [
      ['Action.Acknowledgement'] => [undef],
      ],
      ],
      ]

      Bivio::Test::Request implements new_unit and run_unit, which allows
      Bivio::Test::Unit to have a hook to call req(), and get an initialized
      result. This is similar to the structure we use for acceptance tests.

      Ideally, I would have liked a syntax like:

      Request([
      ...
      ]);

      However, that's not possible in Perl 5, because there is no way to
      defer evaluation without putting the code in a closure (which to my
      mind was unnecessary syntax). The current syntax is clean enough and
      allows other types of setup, anyway, e.g.:

      # $Id: UserRealmList.bunit,v 1.2 2005/09/16 20:03:41 nagler Exp $
      ListModel();
      use Bivio::PetShop::Util;
      req()->set_realm(Bivio::PetShop::Util->DEMO);
      [
      load_all => [
      # There may be orders; We testing find_row_by_type, not load_all.
      [] => undef,
      ],
      find_row_by_type => [
      [Bivio::Auth::RealmType->USER] => sub {[shift->get('object')]},
      [Bivio::Auth::RealmType->CLUB] => [undef],
      ],
      ];

      All these tests are a part of bOP, btw.

      We've also upgraded our b-perl.el to more easily add templates for
      *.bunit, *.btest, etc. And, b-perl.el and b-site-start.el is a part
      of bOP now.

      Have a nice weekend,
      Rob
    Your message has been successfully submitted and would be delivered to recipients shortly.