Arduino:
Tests Schrijven
Hoe te:
#include <Arduino.h>
#include <unity.h>
void setUp(void) {
// stel dingen hier in
}
void tearDown(void) {
// ruim hier op
}
void test_led_builtin_pin_nummer(void) {
TEST_ASSERT_EQUAL(13, LED_BUILTIN);
}
void test_led_status_hoog(void) {
digitalWrite(LED_BUILTIN, HIGH);
TEST_ASSERT_EQUAL(digitalRead(LED_BUILTIN), HIGH);
}
void setup() {
UNITY_BEGIN();
RUN_TEST(test_led_builtin_pin_nummer);
RUN_TEST(test_led_status_hoog);
UNITY_END();
}
void loop() {
// Meestal leeg bij testen
}Uitvoer:
.
.
OKDiep Duiken
Historische context: Testen in Arduino kwam later dan in softwareontwikkeling en was minder gebruikelijk vanwege de interactie met hardware. Alternatieven: Handmatig testen, of meer complexe testraamwerken zoals Google Test. Implementatiedetails: Typisch gebruiken we een bibliotheek zoals ArduinoUnit of AUnit. Plaats testen in setup() en houd loop() leeg aangezien testen eenmalig draaien.
Zie Ook
- ArduinoUnit bibliotheek: https://github.com/mmurdoch/arduinounit
- AUnit bibliotheek: https://github.com/bxparks/AUnit
- Introductie tot Unit Testing: https://www.arduino.cc/en/Guide/UnitTesting