Skip to content

hepabolu/mytap

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

MySQL 5.5 MySQL 5.6 MySQL 5.7 MySQL 8.0 Build Status

MyTAP 1.0

MyTAP is a unit testing framework for MySQL 5.x written using functions and procedures. It includes a collection of Test Anything Protocol (TAP) emitting assertion functions, as well as the ability to integrate with other TAP-emitting test frameworks.

Installation

To install MyTAP to a MySQL server, just run the install script from the mytap directory:

# ./install.sh

This assumes local server access or user and host credentials in ~/.my.cnf.

The installer will create a database called tap with 2 tables, import the base package and any version specific patches. When installation has completed, the test suite will run automatically. Any errors at this point should be raised as issues because it will likely indicate a change in the MySQL information_schema or a bug in a MySQL release against which myTAP has not been tested.

For installations on remote servers, non-standard port numbers, or where client credentials are not stored, provide the appropriate short or long-form switches for the required parameters. e.g.

# ./install.sh --port 3310
# ./install.sh --user root --password rootpassword 2>/dev/null
# ./install.sh -h 127.0.0.1 -P 3310 --u root --p rootpassword 2>/dev/null

The installer can run a subset of the tests with the --filter option

# ./install.sh --filter table

or, to skip the tests entirely

# ./install.sh --no-tests

Finally, it is also possible to run the installer in test-only mode (useful for developers) with

# ./install.sh --no-install

Short-form versions of all of these switches exist, for full details

# ./install.sh --help

###Amazon Aurora MyTAP may be used on Amazon Aurora but the installation script will generate some errors because Aurora does not permit the use of the SUPER privilege which is necessary to set the MySQL Global variable log_bin_trust_function_creators. It is possibile to work around this issue by creating a new parameter group for your Aurora instance and setting this variable in Edit Parameters within the AWS console. Full instructions on a workaround can be found in this answer on Stack Overflow.

https://stackoverflow.com/a/30874794/5870171

This same issue will cause some errors in running the current version of the test scripts for VIEWS and PRIVILEGS which rely on SUPER privilege to define suitable test data.

MyTAP Test Scripts

Here's an example of how to write a MyTAP test script:

-- Start a transaction.
BEGIN;

-- Plan the tests.
SELECT tap.plan(1);

-- Run the tests.
SELECT tap.pass( 'My test passed, w00t!' );

-- Finish the tests and clean up.
CALL tap.finish();
ROLLBACK;

Note how the TAP test functions are referenced from another database so as to keep them separate from your application database.

Now you're ready to run your test script!

% mysql -u root --disable-pager --batch --raw --skip-column-names --unbuffered --database test --execute 'source test.sql'
1..1
ok 1 - My test passed, w00t!

Yeah, that's rather a lot of options to have to remember to get valid tap. I suggest that you install TAP::Parser::SourceHandler::MyTAP instead and just use its my_prove utility:

% my_prove -u root --database test test.sql

Using MyTAP

The purpose of MyTAP is to provide a wide range of testing utilities that output TAP. TAP, or the "Test Anything Protocol", is an emerging standard for representing the output from unit tests. It owes its success to its format as a simple text-based interface that allows for practical machine parsing and high legibility for humans. TAP started life as part of the test harness for Perl but now has implementations in C/C , Python, PHP, JavaScript, Perl, PostgreSQL, and now MySQL.

More information on the use of MyTAP can be found in the documentation.

To Do

  • Port a lot of other assertion functions from pgTAP.

Public Repository

The source code for MyTAP is available on GitHub. Please feel free to fork and contribute!

Authors

Credits

  • Michael Schwern and chromatic for Test::More.
  • Adrian Howard for Test::Exception.

Copyright and License

Copyright (c) 2010 David E. Wheeler, Helma van der Linden. Some rights reserved.

The full license is available in a separate LICENSE file.