{"id":1565,"date":"2012-03-19T13:50:29","date_gmt":"2012-03-19T17:50:29","guid":{"rendered":"http:\/\/hstore.cs.brown.edu\/?page_id=1565"},"modified":"2012-05-24T18:59:27","modified_gmt":"2012-05-24T22:59:27","slug":"writing-new-tests","status":"publish","type":"page","link":"https:\/\/hstore.cs.brown.edu\/documentation\/development\/writing-new-tests\/","title":{"rendered":"Writing New Tests"},"content":{"rendered":"

\u00ab<\/B> Writing New Benchmarks<\/a><\/div>
Writing New System Stored Procedures<\/a> \u00bb<\/B><\/div>
<\/div><\/p>\n

There are two types of test cases in H-Store. The first is a simple unit test<\/a> that checks a small feature of the system’s internals without needing to deploy the entire database. The other type is referred to as a regression test<\/a> which is designed to execute the end-to-end functionality of the entire system. We now describe how to write each of these types of tests.<\/p>\n

<\/a><\/p>\n

Writing a Unit Test Case<\/h2>\n

The testing source code files for the main part of the H-Store system are located in tests\/frontend<\/tt><\/a>. This directory mirrors the heirachy of src\/frontend<\/tt><\/a>. For a given class file in src<\/tt>, there will be a corresponding class file in the same directory in tests<\/tt>, except that the class name will have the Test<\/tt> prefix. That is, if the source class file that you want to write a test case for is called MyClass<\/tt>, then the test class file will be called TestMyClass<\/tt>.<\/p>\n

There is a special abstract class called BaseTestCase<\/tt><\/a> that extends the default JUnit TestCase class. BaseTestCase<\/tt> provides various helper methods for working with built-in benchmarks<\/a> and their catalogs.<\/p>\n

For example, the following test case will automatically create the TPC-C project catalog for each test case. After the setUp()<\/tt> method is complete, the test cases can retrieve various objects from compiled Catalog<\/tt> using the
\nBaseTestCase<\/tt> API:<\/p>\n\n

public<\/span> class<\/span> TestExample extends<\/span> BaseTestCase {<\/span>\n    @Override\n    protected<\/span> void<\/span> setUp(<\/span>)<\/span> throws<\/span> Exception<\/span> {<\/span>\n        super<\/span>.setUp<\/span>(<\/span>ProjectType.TPCC<\/span>)<\/span>;<\/span>\n    }<\/span>\n \n    public<\/span> void<\/span> testExample(<\/span>)<\/span> {<\/span>\n        Catalog catalog =<\/span> getCatalog(<\/span>)<\/span>;<\/span>\n        Database catalog_db =<\/span> getDatabase(<\/span>)<\/span>;<\/span>\n        \/\/ Additional testing code...<\/span>\n    }<\/span>\n}<\/span><\/pre><\/td><\/tr><\/table><\/div>\n\n

<\/a><\/p>\n

Writing a Regression Test<\/h2>\n

A regression test case is more involved. The test case will need to extend the RegressionSuite<\/tt><\/a> base class. The implementing class will need to include a suite()<\/tt> method that returns a MultiConfigSuiteBuilder<\/tt>. It is here that one must declare what cluster configurations to execute for each of the test cases. Each test case will be executed
\nonce for each of these configurations.<\/p>\n