feat: add Test for WifiConnect API

This commit is contained in:
Mathis 2023-04-24 12:22:52 +02:00
parent 9811022b76
commit 5784e38fbb
7 changed files with 71 additions and 14 deletions

13
.vscode/settings.json vendored Normal file
View File

@ -0,0 +1,13 @@
{
"files.associations": {
"__bit_reference": "cpp",
"__hash_table": "cpp",
"__split_buffer": "cpp",
"array": "cpp",
"initializer_list": "cpp",
"string": "cpp",
"string_view": "cpp",
"unordered_map": "cpp",
"vector": "cpp"
}
}

View File

@ -1,4 +1,10 @@
; Add additionnal environments in this file
; Debug environemnt
[env:test]
test_build_src = true
build_type = debug
build_flags = ${env.build_flags}
-D TESTING
; Default production environment
[env:prod]

View File

@ -1,12 +0,0 @@
; Add secrets token/logins/etc `secrets.ini`
; Add the sames values as blank in `secrets.ini.example
; To be able to reproduce it
[secrets]
build_flags =
-D WIFI_SSID=\"...\"
-D WIFI_PASSWORD=\"...\"4
-D USER_NAME=\"...\"
-D USER_PASSWORD=\"...\"

View File

@ -1,12 +1,16 @@
#ifndef TESTING
#include <Arduino.h>
#include "Program.h"
Program* program;
void setup() {
program = new Program();
program = new Program();
}
void loop() {
program->loop();
program->loop();
}
#endif

20
IOT/test/main.cpp Normal file
View File

@ -0,0 +1,20 @@
#include <Arduino.h>
#include <unity.h>
#include "test.h"
void setup() {
delay(2000);
// start unit tests engine
UNITY_BEGIN();
Serial.begin(115200);
RUN_TEST(TestWifiBeginConnected);
RUN_TEST(TestWifiBeginNotConnected);
UNITY_END();
}
void loop() {
}

7
IOT/test/test.h Normal file
View File

@ -0,0 +1,7 @@
#ifndef TEST_H
#define TEST_H
void TestWifiBeginConnected();
void TestWifiBeginNotConnected();
#endif

19
IOT/test/test_api.cpp Normal file
View File

@ -0,0 +1,19 @@
#include "test.h"
#include <unity.h>
#include "API.h"
void TestWifiBeginConnected() {
API* api = new API(USER_NAME, USER_PASSWORD, API_HOST);
Serial1.begin(MONITOR_SPEED);
TEST_ASSERT_EQUAL_MESSAGE(true, api->wifiBegin(WIFI_SSID, WIFI_PASSWORD, &Serial1), "Wifi not connected");
}
void TestWifiBeginNotConnected() {
API* api = new API(USER_NAME, USER_PASSWORD, API_HOST);
Serial2.begin(MONITOR_SPEED);
TEST_ASSERT_EQUAL_MESSAGE(false, api->wifiBegin(WIFI_SSID, WIFI_PASSWORD, &Serial2), "Wifi connected");
}