Presentation is loading. Please wait.

Presentation is loading. Please wait.

Christian Hujer What is AceUnit? How does AceUnit work? How do I use AceUnit? 2007-12-161© 2007 Christian Hujer.

Similar presentations


Presentation on theme: "Christian Hujer What is AceUnit? How does AceUnit work? How do I use AceUnit? 2007-12-161© 2007 Christian Hujer."— Presentation transcript:

1 Christian Hujer What is AceUnit? How does AceUnit work? How do I use AceUnit? 2007-12-161© 2007 Christian Hujer

2 What is AceUnit? Why Unit Test? Requirements, Relationship to other Frameworks 2007-12-16© 2007 Christian Hujer2

3  Find bugs early  Prevent regression  Speedup development  Embrace change / Refactoring  Grey Box Testing 2007-12-163© 2007 Christian Hujer

4  Easy to use  As close to JUnit 4.x as possible  Highly Configurable and Adoptable  Suits "normal" and embedded development  Logging compatible with JUnit  Low memory consumption and footprint  High degree of convenience 2007-12-164© 2007 Christian Hujer

5 2007-12-165© 2007 Christian Hujer

6  Advanced C and Embedded Unit  Unit Test Framework for C (C89 and C99)  Open Source (License: BSD (revised))  Target environment:  Desktop  Embedded  Architecture based on JUnit 4.x:  Uses Annotations  Uses Reflection 2007-12-166© 2007 Christian Hujer

7  Further Information  AceUnit:http://aceunit.sourcefourge.net/http://aceunit.sourcefourge.net/  CUnit:http://cunit.sourceforge.net/http://cunit.sourceforge.net/  EmbUnit:http://embunit.sourceforge.net/http://embunit.sourceforge.net/  JUnit:http://junit.sourceforge.net/http://junit.sourceforge.net/  Questions? 2007-12-167© 2007 Christian Hujer

8 AceUnit Components AceUnit Framework 2007-12-16© 2007 Christian Hujer8

9 2007-12-169© 2007 Christian Hujer

10 2007-12-16© 2007 Christian Hujer10 SuiteFixture Runner Logger Assert Tests Data

11  Further Information  AceUnit: http://aceunit.sourceforge.net/http://aceunit.sourceforge.net/  Questions? 2007-12-1611© 2007 Christian Hujer

12 Writing Tests Using Assertions Integrating AceUnit in your build Configuring AceUnit 2007-12-16© 2007 Christian Hujer12

13  Annotations  Fixtures  Assertions  Suites  Logging 2007-12-1613© 2007 Christian Hujer

14  Programming Languages: Java, C#  Metadata about members and other accessible elements  Examples (Java):  @PrimaryKey private String key;  @NotNull private String name;  void setColor(@Nullable final Color color); 2007-12-16© 2007 Christian Hujer14

15 Like JUnit 4.x. No '@' in C -> 'A_' instead. Default: #defined as empty macros  A_Test  Test case  A_Before, A_After  Executed before / after each test case  A_BeforeClass, A_AfterClass  Executed at start / end of fixture 2007-12-1615© 2007 Christian Hujer

16  Collection of test cases with same preconditions  Test source = test class = fixture 2007-12-1616© 2007 Christian Hujer

17 /** @file fooTest.c */ /* fooTest.h generated by AceUnit Generator */ #include "fooTest.h" /** Some test case. */ A_Test void testFoo1() {…} /** Another test case. */ A_Test void testFoo2() {…} 2007-12-1617© 2007 Christian Hujer

18  Verification is done with Assertions  See AceUnit documentation for list  You can define your own Assertions  Pattern: assertXXX(message, params)  #define ACEUNIT_EMBEDDED:  message is ignored  Instead uses line number as uint16_t 2007-12-1618© 2007 Christian Hujer

19 /** My test case. */ A_Test void testFoo1() { #define EXPECTED = 42; uint16_t actual = getAnswer(); assertEquals("Expected answer to be 42.", EXPECTED, actual); } 2007-12-1619© 2007 Christian Hujer

20  Test Case Setup / Teardown  Prepare data for / cleanup after each test case  Like setUp() / tearDown() in JUnit 3.x  Like @Before / @After in JUnit 4.x  Multiple A_Before / A_After possible  Execution order = order in source code 2007-12-1620© 2007 Christian Hujer

21 static Foo_t *foo; A_Before void createFoo() { foo = (Foo_t *) malloc(sizeof(Foo_t)); bzero(foo, sizeof(Foo_t)); } A_After void destroyFoo() { free(foo); } 2007-12-1621© 2007 Christian Hujer

22  Prepare data for all tests  Fixture Setup / Teardown  Like @BeforeClass / @AfterClass in JUnit 4.x  New in JUnit 4.x / AceUnit  Multiple A_BeforeClass / A_AfterClass possible  Execution order = order in source code 2007-12-1622© 2007 Christian Hujer

23 static Foo_t *foo; A_BeforeClass void allocateFoo() { foo = (Foo_t *) malloc(sizeof(Foo_t)); } A_Before void initFoo() { bzero(foo, sizeof(Foo_t)); } A_AfterClass void freeFoo() { free(foo); } 2007-12-1623© 2007 Christian Hujer

24 2007-12-1624© 2007 Christian Hujer

25  A_Test, A_Before etc.  Must be on same line as annotated method  Should be before other modifiers of method  ACEUNIT_STATIC_ANNOTATIONS  Define this to #define annotations static  Pro: No name clashes between fixtures  Con: Problems with some debuggers 2007-12-1625© 2007 Christian Hujer

26  aceunit/src/native  Add to include search path  Add to C search path  Before compilation  Run generator  Include in compilation:  AceUnit.c  AceUnitData.c  Logger of your choice 2007-12-1626© 2007 Christian Hujer

27  ACEUNIT_EMBEDDED  Use AceUnit in embedded mode  less footprint  uint16_t instead of char*  ACEUNIT_C99  Use AceUnit with C99 instead of C89/C90.  ACEUNIT_STATIC_ANNOTATIONS  #define A_* static 2007-12-1627© 2007 Christian Hujer

28  ACEUNIT_CODE_INCLUDE  Define file to include for code (ROM).  Use for section information.  ACEUNIT_DATA_INCLUDE  Define a file to include before variables (RAM).  Use for section information. 2007-12-16© 2007 Christian Hujer28

29  ACEUNIT_ASSERTION_STYLE  Define how to "implement" fail  Possible values: ▪ ACEUNIT_ASSERTION_STYLE_RETURN ▪ ACEUNIT_ASSERTION_STYLE_ASSERT ▪ ACEUNIT_ASSERTION_STYLE_ABORT ▪ ACEUNIT_ASSERTION_STYLE_LONGJMP ▪ ACEUNIT_ASSERTION_STYLE_CUSTOM ▪ -> Define ACEUNIT_CUSTOM_ASSERT() 2007-12-16© 2007 Christian Hujer29

30  Small Java Program  Creates headers for fixtures  "Connects" your fixtures with AceUnit  Requires JRE 1.5 or newer 2007-12-16© 2007 Christian Hujer30

31  Arguments:  List of Suite names ▪ Packages (directories, will be searched recursively) ▪ Fixtures (omit.c suffix!)  Options:  --exit Quit Java VM with error code. (Use!)  -h, --help: Display help and exit.  -f, --force: Overwrite write-protected files. 2007-12-16© 2007 Christian Hujer31

32  Example (in a Makefile): prepareAceUnit: java -jar AceUnit.jar --exit src/  Example (Batch): java -jar AceUnit.jar --exit src/ && cc $(find –name *.c) -o runTests &&./runTests 2007-12-16© 2007 Christian Hujer32

33  Questions? 2007-12-16© 2007 Christian Hujer33

34 Footprint, Future Unit Tests in Software Engineering 2007-12-16© 2007 Christian Hujer34

35 In bytes for 32 Bit with ACEUNIT_EMBEDDED  Code (constant data, anywhere)  4 per annotated methods  48 per Fixture  2 per test case  Plus code (testling and fixture)  Data (variable data, RAM)  16 for Runner  N*2 for Logging (MiniRamLogger, N = log failures)  1 Jump Buffer (if setjmp()/longjmp() is used) 2007-12-1635© 2007 Christian Hujer

36  5 Fixtures with 40 methods, 30 test cases  Code:  4 * 40 + 48 * 5 + 2 * 30 plus code  = 460 plus code  Data (5 failure entries):  16 + 5 * 2 + Jump Buffer  = 26 + Jump Buffer 2007-12-1636© 2007 Christian Hujer

37  Generator  Ant Task for Java Generator (Q1 2008)  Alternative Perl Generator (Q1 2008)  Alternative C Generator (?)  Framework  More Assertions (Q1 2008)  Internal Refactoring (encapsulation, public API) (?)  Pluggable Runners (Q2 2008)  Support of Suites (Q2 2008) 2007-12-16© 2007 Christian Hujer37

38 2007-12-16© 2007 Christian Hujer38

39  Thanks for Listening!  Questions? 2007-12-16© 2007 Christian Hujer39


Download ppt "Christian Hujer What is AceUnit? How does AceUnit work? How do I use AceUnit? 2007-12-161© 2007 Christian Hujer."

Similar presentations


Ads by Google