title: Unit testing an Arduino Class
body: <p>I'm currently working on a embedded system project and we are prototyping the hardware using an Arduino Uno. So far, we need to be able to get reliable temperature readings from a temperature sensor (TMP36) and I've managed to write a library/class for this specific sensor. You can find it here:<br>
  TMP36.h  </p>
  
  <pre><code>#include &lt;Arduino.h&gt;
  
  class TMP36
  {
      public:
          TMP36(int pino);
          float getTempC();
          void setLimSup(float a);
          void setLimInf(float a);
          void testLimSup();
          void testLimInf();
      private:
          float _limSup;
          float _limInf;
          int _pino;
          float _tensao;
          float getTensao();
  };
  </code></pre>
  
  <p>TMP36.cpp  </p>
  
  <pre><code>#include "Arduino.h"
  #include "TMP36.h"
  #include "ArduinoUnit.h"
  
  TMP36::TMP36 (int pino)
  {
      _pino = pino;
  }
  
  float TMP36::getVoltage()
  {
      return (analogRead(_pino) * 0.004882814);
  }
  
  float TMP36::getTempC ()
  {  
      _tensao = getVoltage();
      return (_tensao - 0.5) * 100.0;
  }
  
  void TMP36::setLimSup(float a)
  {
      _limSup = a;
  }
  
  void TMP36::setLimInf(float a)
  {
      _limInf = a;
  }
  
  void TMP36::testeLimSup()
  {
      test(okLimSup)
      {
          float reading = getTempC();
          AssertLessOrEqual(reading, _limSup);
      }
  
  }
  
  void TMP36::testeLimInf()
  {
  
      test()
      {
          float reading = getTempC();
          assertMoreOrEqual(reading, _limInf);
      }
  }
  </code></pre>
  
  <p>To be able to test if the getTempC is within the sensor range, I've been messing around with <a href="https://github.com/mmurdoch/arduinounit" rel="nofollow">ArduinoUnit 2</a>, but when compiling this code:</p>
  
  <pre><code>#include "TMP36.h"
  
  TMP36 tmp36(0);
  
  void setup() {
    Serial.begin(9600);
  
  }
  
  void loop() {
    float temp;
    temp = tmp36.getTempC();
    Serial.println(temp);
    delay(1000);
  
  }
  </code></pre>
  
  <p>on Arduino IDE I get the following errors:</p>
  
  <pre><code>In file included from /media/pedro/Storage/Linux/Arduino/arduino-1.6.11/libraries/TMP36/TMP36.cpp:3:0:
  /media/pedro/Storage/Linux/Arduino/arduino-1.6.11/libraries/TMP36/TMP36.cpp: In member function 'void TMP36::testeLimSup()':
  /media/pedro/Storage/Linux/Arduino/arduino-1.6.11/libraries/ArduinoUnit/ArduinoUnit.h:591:164: error: qualified-id in declaration before '(' token
   #define test(name) struct test_ ## name : TestOnce { test_ ## name() : TestOnce(F(#name)) {}; void once(); } test_ ## name ## _instance; void test_ ## name :: once() 
                                                                                                                                                                      ^
  /media/pedro/Storage/Linux/Arduino/arduino-1.6.11/libraries/TMP36/TMP36.cpp:34:2: note: in expansion of macro 'test'
    test(okLimSup)
    ^
  /media/pedro/Storage/Linux/Arduino/arduino-1.6.11/libraries/TMP36/TMP36.cpp: In member function 'void TMP36::testeLimInf()':
  /media/pedro/Storage/Linux/Arduino/arduino-1.6.11/libraries/ArduinoUnit/ArduinoUnit.h:591:164: error: qualified-id in declaration before '(' token
   #define test(name) struct test_ ## name : TestOnce { test_ ## name() : TestOnce(F(#name)) {}; void once(); } test_ ## name ## _instance; void test_ ## name :: once() 
                                                                                                                                                                      ^
  /media/pedro/Storage/Linux/Arduino/arduino-1.6.11/libraries/TMP36/TMP36.cpp:45:2: note: in expansion of macro 'test'
    test()
    ^
  /media/pedro/Storage/Linux/Arduino/arduino-1.6.11/libraries/TMP36/TMP36.cpp:50:1: error: expected '}' at end of input
   }
   ^
  exit status 1
  Error compiling for board Arduino/Genuino Uno.
  </code></pre>
  
  <p>Since this is my first time UnitTesting, I'm not quite sure what does errors mean, so I need help fixing them.</p>
  
  <p>Thank you!</p>