Giter Site home page Giter Site logo

goose_test's Introduction

Goose Test

What is it?

A simple, intuitive, header-only unit test framework for C++11 code.

#include <test/goose_test.hpp>
#include <stdlib/string.hpp>

test_case(StringTest, String)
{
    goose::string x = "hello";
    expect_cstr_equal("hello", x.c_str());
}

It Kinda Reminds Me of Another Popular Test Framework

This code may remind you of another framework, but I found that I wanted something compact, implemented only with headers, MIT-licensed, and used terms like "test case" and "test suite" more intuitively.

A Test Case...

...is a function implemented to exercise a given behavior in the target code under test (CUT). In Goose Test, each test case is defined within its own function, declared using the provided test_case macro. Test cases by default stand alone and share no state with each other.

A Test Suite...

...is a collection of related test cases. While test cases are assumed to stand alone, a facility exists to share state between them if needed. For example, a Test Suite may depend on a network resource that may be nontrivial to create and destroy. Your test code can extend the TestSuite class to encapsulate shared state between test cases. Virtual methods start and end are called at the start, and end, of each test case sharing a TestSuite.

Sample Test Suite

struct CustomTestSuite : goose::TestSuite
{
    virtual void start()
    {
        // Called before the SanityCheck test case runs
        shared_state = 5;
    }

    virtual void end()
    {
        // Called after the SanityCheck test case runs
    }

    unsigned int shared_state = 0;
};

suite_test_case(CustomTestSuite, SanityCheck)
{
    expect_equal(5, shared_state);
}

Deployment

You can copy the headers directly into your project, or use this repo as a git submodule (https://git-scm.com/book/en/v2/Git-Tools-Submodules), or just copy whatever you'd like from here within the guidelines of the MIT license. To save you the boilerplate, a custom main function for the test application targeting the CUT is provided that will register your test cases with the internal test framework automagically. You need only include the goose_test.hpp header and you're off to testland.

Supported Compilers

TODOs

  • Fill-out the Supported Compilers section.
  • Supply inline documentation for macros and Test Suite to generate online help
  • Supply working examples
  • Provide cookie-cutter support for statically initialized data members in TestSuite

goose_test's People

Contributors

davidgosselin avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.