easyunit

EasyUnit - An easy C++ unit testing framework

EasyUnit

a unit testing framework for C++ which is extremely simple and easily customizable;EC++ compatible for embedded version (no STL, RTTI, multiple inheritance and exceptions);no boilerplate code : 0 line, none, niet, nada;results output and test execution are entirely customizable;default configuration are optimized for general needs;based on Michael Feathers' CppUnitLite framework.

EasyUnit : Simple, Easy, Efficient

EasyUnit was created to ease creation and use of unit testing in C++. Most of the existing frameworks ask programmers to create objects and use macros to administer test cases in addition to write their own test cases. It is the author belief that boilerplate code and taking care of test administration discourage programmers and students to use unit testing even if it is representing one line of code per test case.

EasyUnit : Embedded and Standard version

EasyUnit is delivered in two versions:EasyUnit embedded version is fully compatible with EC++ and contains only a minimum of classes.EasyUnit standard version adds exception handling and more customization. Key differences from embedded version are:Exceptions detection. This makes EasyUnit incompatible with EC++.More testprinters (output customization) and testrunners (testcase filter). Those add-ons are available in a separate package for the embedded version.

EasyUnit Examples (v. 1.0 Beta2)

Simple example

// Stack.h

class Stack {

public: 
  int size();
  bool isEmpty();

};

// Stack.cpp

#include "Stack.h"

int Stack::size() { return 0; }

bool Stack::isEmpty() { return true; }

// StackTest.cpp

#include "easyunit/test.h" 
#include "Stack.h" 

using namespace easyunit;

TEST(Stack,size)
{
  Stack s;
  ASSERT_TRUE(s.size() == 1); 
}

TEST(Stack,isEmpty)
{
  Stack s;
  ASSERT_TRUE(s.isEmpty()); 
}

// main.cpp

#include "easyunit/testharness.h" 

using namespace easyunit;

int main() 
{

  TestRegistry::runAndPrint();

}

// Console output:

-- EasyUnit Results --

SUMMARY

Test summary: FAIL
Number of test cases ran: 1
Test cases that succeeded: 0
Test cases with errors: 0
Test cases that failed: 1

DETAILS

Test case "Stack" FAILED with 0 error(s), 1 failure(s) and 1 success(es):
  Test "size" FAILED :
    Failure: "s.size() == 1" line 11 in StackTest.cpp
  Test "isEmpty" SUCCEEDED!


Example with fixtures

// Stack.h

class Stack {

public:
  int size();
  bool isEmpty();

};

// Stack.cpp

#include "Stack.h"

int Stack::size() { return 0; }

bool Stack::isEmpty() { return true; }

// Queue.h

class Queue {

public:
  void setSize(long s) {size_ = s); 
  long size() {return size_;}
  bool isEmpty() {return true;}

private:
  long size; 

};

// QueueTest.cpp

#include "easyunit/test.h" 
#include "Queue.h" 

using namespace easyunit;

DECLARE(CustomQueue)
  Queue *q;
END_DECLARE

SETUP(CustomQueue)
{
  q = new Queue();
  q->setSize(100);
}

TEARDOWN(CustomQueue)
{
  delete q; 
}

TESTF(CustomQueue,test1)
{
  ASSERT_TRUE(q->isEmpty());
  ASSERT_TRUE(q->size() == 0); 
}

TESTF(CustomQueue,test2)
{
  FAIL_M("Buffer overflow");
}

// StackTest.cpp

#include "easyunit/test.h" 
#include "Stack.h"

using namespace easyunit;

TEST(Stack,size)
{
  Stack s;
  ASSERT_TRUE(s.size() == 0); 
}

TEST(Stack,isEmpty)
{
  Stack s;
  ASSERT_TRUE(s.isEmpty()); 
}

// main.cpp

#include "easyunit/testharness.h" 

using namespace easyunit;

int main() 
{

  TestRegistry::runAndPrint();

}

// Console output:

-- EasyUnit Results --

SUMMARY

Test summary: FAIL
Number of test cases ran: 2
Test cases that succeeded: 1
Test cases with errors: 0
Test cases that failed: 1

DETAILS

Test case "Stack" SUCCEEDED with 0 error(s), 0 failure(s) and 2 success(es):
  Test "size" SUCCEEDED!
  Test "isEmpty" SUCCEEDED!

Test case "CustomQueue" FAILED with 0 error(s), 2 failure(s) and 0 success(es):
  Test "test1" FAILED :
    Failure: "q->size() == 0" line 26 in QueueTest.cpp
  Test "test2" FAILED :
    Failure: "Buffer overflow" line 31 in QueueTest.cpp



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值