trendlop.blogg.se

Unity cmock tutorial
Unity cmock tutorial








unity cmock tutorial

TEST_ASSERT_EQUAL_STRING( "Attention, Dr. In fact, Unity can handle all sorts of types, not just integers. It's printed clearly in a format that is most convenient to you, the test writer. The second argument is the value you are testing. Isn't that nice? The first argument is the expected value. TestMyModule.c:31:test_Three:FAIL:Expected 32768 was 1 TestMyModule.c:23:test_Two:FAIL:Expected 0x05 was 0x01 Which, if run in separate tests, would lead to the following failures: TestMyModule.c:15:test_One:FAIL:Expected 2 was 1 Which results in: TestMyModule.c:15:test_one:FAIL:a isn't 2, end of the world!Īnd then there is the elegant solution, using Unity's multitude of pretty assertions: TEST_ASSERT_EQUAL_INT(2, a) The brute force method (good for your non-standard corner cases): TEST_ASSERT_MESSAGE( a = 2, "a isn't 2, end of the world!")

unity cmock tutorial

While correct, it's not terribly informative.

unity cmock tutorial

but when something went wrong, you'd see something like this: TestMyModule.c:15:test_One:FAIL You could use nothing but the TEST_ASSERT above, and you could test almost anything that your C code can handle. TEST_ASSERT( a = 2 ) //this one will fail TEST_ASSERT( a = 1 ) //this one will pass At their most basic, they are things like this: int a = 1 Assertions are statements of what we expect to be true about our embedded system. Unity is most obviously about assertions.










Unity cmock tutorial