Download presentation
Presentation is loading. Please wait.
Published byMelvin Harmon Modified over 6 years ago
1
Systems Programming 3rd laboratory Test_driven Development
Unit Testing Read the assignment till the end The slides with the descritionof the probeblme are marked with: The slides with the actual steps of work are marked with:
2
Laboratory exercise Using the TDD methodology
implement a stack of integers module The module should export the following functions create_stack size push pop top The first version of the stack should use a static array (int v[5]) to store the values
3
Module Interface Requirements
create_stack parameters () return: pointer to stack Creates the necessary data structure and returns a pointer to it size parameters: (pointer to stack) return: integer Returns the number of integers top Returns the integer on top of the stack
4
Module Interface Requirements
push parameters (pointer to stack, integer value) return: void places the integer on top of the stack pop parameters (pointer to stack) remove the integer on top of the stack
5
Development steps Using ceedling and unity, develop the code along with the tests. Development steps Creation of project Addition of module definition of first function to implement Implementation of tests Execution of tests loop
6
1 Creation of project Creation of project ceedling new stack_project
update project.yml Addition of module cd stack_project rake module:create[int_stack]
7
Ceedling / Unity Ceedling ceedling new stack_project
rake module:create[int_stack] rake test:all Unity TEST_ASSERT_EQUAL_INT(expected, actual) TEST_ASSERT_FLOAT_WITHIN(delta, expected, actual) TEST_ASSERT_NULL(pointer) TEST_ASSERT_NOT_NULL(pointer)
8
2 First test edit test/test_int_stack.c Create a stack
verify if pointer not NULL verify its size You can copy the content of the file in FENIX If you run the test compilation errors will be issued: int_stack not defined #include "unity.h" #include "int_stack.h" int_stack * s; void setUp(void){ s = create_stack(); } void tearDown(void){ void test_task_creation(){ TEST_ASSERT_NOT_ NULL(s); int n = size(s); TEST_ASSERT_EQUA L_INT(0,n);
9
First test #include "unity.h" #include "int_stack.h" int_stack * s;
void setUp(void){ s = create_stack(); } void tearDown(void){ void test_task_creation(){ TEST_ASSERT_NOT_NULL(s); int n = size(s); TEST_ASSERT_EQUAL_INT(0,n); Global variable, know by all tests Initialization of global variables Executed before any test Executed after any test One simple test. Other tests should be implemented in different functions
10
First test Now that we have a failing test we should
define the type (typede) implement the necessary functions Just write the typedef Just implement the functions: create_stack() size(s) DO NOT IMPLEMENT ANY OTHER FUNCTION!!!!
11
3 First test Write src/int_stack.h typedef function headers
write src/int_stack.c implement function create_stack / size Run test
12
At this stage we know stack creation is working +- The size of an empty stack is correct :) We should now write more complex tests push elements and verify the stack size push elements above stack limit code should not break
13
4 Next Steps Write tests to verify push exercise push exercise size
exercise limit of the stack Implement push write test to verify top use push Implement top
14
5 Top? What to Top? First test: try to top from a empty stack
Test should be successful!!!! What to top when stack is empty? Rewrite API :( Rewrite test
15
6 Next Steps Write tests to verify pop exercise pop exercise size
exercise limit of the stack Implement pop write test to verify top After pop
16
Modify implementation
7 Modify implementation Change the stack implementation to allow dynamic arrays When doing a push grow the array that stores the values as needed re-run tests and verify results
17
Unity Documentation github.com/ThrowTheSwitch/Unity/tree/ master/docs
html
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.