ESP8266 Unit Testing - Part 2/2: GoogleTest and GoogleMock - Day 33 of #100DaysOfCode​ in IoT

preview_player
Показать описание
Part 2 of unit testing with ESP8266. Today I focused on GoogleTest, created few example tests testing example code, and then I moved on to testing my Core library functionalities with the use of mocks with GoogleMock...

You can find the code from this episode here:
Add and Multiply function tests:
UniUno tests:

GoogleTest Documentation:

Social Media:

Software used in the video:
1. Visual Studio Code IDE:
2. C/C++ VSCode extension:
3. Clang-Format VSCode extension:
4. PlatformIO VSCode extension:

Thanks for watching and see you tomorrow!

00:00:00 Intro
00:00:14 Where I finished yesterday
00:01:55 Clean up
00:03:25 How to configure tests to run (reminder)
00:05:10 Installing and configuring googletest
00:07:28 Initializing googletest
00:08:40 Documentation and first unit test
00:13:05 Running the test
00:15:45 Multiple test files and test files next to production code vs test files in the test folder
00:21:42 Unit testing in an embedded environment
00:28:08 Running embedded tests
00:29:25 Issue with googletest support on PlatformIO and the fix
00:32:15 Trying to break the test by breaking production code
00:34:16 Introduction to googlemock and pasting in Core lib files
00:35:50 My goal with IoT framework as for the prototyping tool
00:36:58 How to mock with googlemock on real-world example with EventDispatcher
00:55:40 Matchers explanation
00:58:08 Running the test with mock and fixing the issue
00:59:55 Breaking code to check if tests fail
01:01:07 Expect mocks to be called in sequence
01:04:24 Another test for EventDispatcher::once method
01:07:20 How I implemented unit tests for Timer class
01:13:36 Plan for tomorrow
Рекомендации по теме
Комментарии
Автор

As always, best tutorials have just a couple of thousand of views

Auline
Автор

Nice video, thank you very much Tomasz!
1) You could and probably should place the hpp and cpp files under lib in subfolders. More Infos should be the in the README of the lib folder.
2) If you use -lgtest_main as build_flags in platformio.ini, you also don't need the google test "int main(){...}" declaration.
3) To build on my machine I need the following entry for native in platformio.ini:
platform = native
test_ignore = test_embedded
lib_compat_mode = off
build_flags =
-lpthread
-lgtest_main
lib_deps = google/googletest@^1.10.0

My folder Structure:
lib
lib/example
lib/example/example.hpp
lib/example/example.cpp
test
test/test_desktop
test/test_desktop/Bla1

test/test_desktop/Bla2


Maybe it helps you or somebody else :)

chachan
visit shbcf.ru