简体   繁体   中英

unit testing Embedded Source Code using GTEST / GMOCK

I am newbie to unit testing, I have basic doubt regarding unit testing, I have middle ware code which needs to be unit tested using gtest/gmock , My Middle ware Code talks with Stack code which come as library.so and my stack library talks with Embedded Hardware, So below are few questions I have

(1) Does Unit Testing means, It should done without Hardware?, I mean writing stub code for stack since stack talks with H/w and test middle ware functionality on PC, In that case developers has to know what events stack sends, when some operation is performed and mimic it in stub code

or

(2) Unit Testing means testing by writing test cases from middle ware code which will talk with stack and then to H/w and catch events from from H/W, then to stack and then to Application and, Assert on Events, to test whether test case is case Pass/Fail

Below is diagram, I intend to unit testing to middle ware code using gtest, My Middle ware is application and stack is.so

在此处输入图像描述

You need to make up your mind, what you want to test. Specifying and implementing tests is an advanced topic, commonly not suited for beginners. Please read some good texts about testing.

Disclaimer: The following is expressed rather loosely, not in formally correct language.

Unit-tests commonly test units, hence the name. A unit can be a class or a module.

The unit-under-test will be the only part of the product, which is linked to the test program(s).

Many frameworks including Googletest provide a lot of "infrastructure" to build test harnesses. The tests stimulate the unit-under-test and check that it reacts as expected. The tests also provide the mocks and stubs that make up the necessary environment of the unit-under-test.

So your first idea is correct. The test developer needs to know how the "neightboring" parts work, and how the unit-under-test is supposed to work. How else can she create a test?

That does not mean that she will need to implement a complete simulation of the "stack" and hardware, in your example. It suffices to implement the behaviour that is important for the aspect that is tested. For example, if you have a timer in the "stack" or the hardware, you could let this timer run faster or slower than in reality.

You could test you app using Mocks or Stubs when you emulate reaction of hardware on specific actions. In this case you acts as you suppose hardware acts and therefore you could check reaction on you software algorithms and check with expected behavior. Or you could write integrational test and interact with you hardware API as request-response. I wrote a lot of such tests, but you always needs a hardware. There are a lot of examples how to write and use different testing frameworks. I could attach my own C++ project with tests see ie https://github.com/IzyaSoft/EasyCli . I have here 2 Eclipse project: one - library (.so) and one - console (that links my library and GTESTS framework).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM