Skip to content
Permalink
Browse files
  • Loading branch information
Mark Tyers committed Mar 13, 2018
2 parents 6c50675 + acf21b2 commit 2d262c7ab65c654aab2cb85dc48486420c1b5fa3
Show file tree
Hide file tree
Showing 9 changed files with 146 additions and 8 deletions.
@@ -1,7 +1,7 @@

# Non-Functional Testing

Lets start by adding a suite of tests to improve the general code quality. These won't test how well the code solves the user stories.
Lets start by adding a suite of tests to improve the general code quality. These won't test how well the code solves the user stories. Refer to the [lecture slides](https://drive.google.com/open?id=1TAyjgDdy-812mwhqrRCVT_MPNhvwApjsAJACmaSqSV8).

## 1 Review Meeting

@@ -1,6 +1,10 @@

# Configuring ESP8266 Development Using the Arduino IDE

Although the IoT kit comes complete with an [ESP8266 development board](https://www.losant.com/blog/top-6-esp8266-modules) which can be programmed in C++ using the [Arduino IDE](https://www.arduino.cc/en/Main/Software) or with [MicroPython](https://docs.micropython.org/en/latest/esp8266/esp8266/tutorial/intro.html), you should only use it if you are already familiar with either of these development environments. If not you are advised to use whatever microcontroller and tool chain you are most comfortable with.

The rest of this worksheet covers setting up the Arduino IDE to be able to use it to create scripts and flash them.

You will need to install drivers on your computer. Look on the base of the NodeCMU. If it states you need the **2102 driver** you can download and install [here](https://www.silabs.com/products/development-tools/software/usb-to-uart-bridge-vcp-drivers).

Install the Arduino IDE
@@ -9,6 +13,8 @@ Install the [CH340 Drivers](https://sparks.gogo.co.nz/ch340.html) for your chose

You may need to install the [NodeMCU Drivers](https://github.com/nodemcu/nodemcu-devkit/tree/master/Drivers) for your chosen platform.

Here are the [Official FTDI Drivers](http://www.ftdichip.com/Drivers/VCP.htm) for the different operating systems.

Arduino > Preferences

Paste the following into the **Additional Boards Manager** box.
@@ -19,15 +25,17 @@ Click on OK to close the Preferences window

Tools > Boards > Board manager.

find `esp8266 by esp8266 community` and install.
find `esp8266 by esp8266 community` and install the latest version (2.4.0 at the time of writing).

## Board setup for programming

After installing the drivers, you can choose the correct board in your IDE.

In Arduino IDE --> Tools --> Board --> Generic ESP8266 Module
In Arduino IDE --> Tools --> Board --> NodeMCU 1.0 (ESP 12E Module)

If the sketch doesn't upload correctly you may need to change the board type to `NodeMCU 1.0 (ESP 12E Module)`.
If the option is available, modify the reset method in Arduino IDE to "nodemcu" by selecting `Tools -> Reset Method -> nodemcu`.

If the sketch doesn't upload correctly you may need to change the board type to `Generic ESP8266 Module`.

NOTE

@@ -37,8 +45,6 @@ To find out the COM port that the arduino is plugged into, you can unplug the ar

On a Mac the port looks like `/dev/cu-wchusbserial1460`.

You may need to modify the reset method in Arduino IDE to "nodemcu". You can do this by selecting Tools --> Reset Method --> nodemcu.

To find out which COM port you have connected your NodeMCU development board to, you can use Device Manager or a Serial Watcher [Apps Anywhere](https://appsanywhere.coventry.ac.uk/) program.

For programming you will need to select the COM port and Baud Rate 115200 Upload Speed.
@@ -0,0 +1,10 @@

#include "Maths.h"

// this is the function we are going to test
// note that there are no API calls in this fucntion
// the function only contains our business logic.
int Maths::add(int a, int b) {
return a + b;
}

@@ -0,0 +1,8 @@



class Maths {
public:
int add(int, int); // this is the function we are going to test
};

@@ -27,7 +27,53 @@ https://github.com/buserror/simavr

https://github.com/covcom/122COM/blob/2016-17_jan/testinglecture_handout.pdf

todo more
## Creating your first Cxx Test

### Install CxxTest and get g++

This process can be done from command line on Windows or Mac. Just make sure you have a C++ compiler installed (e.g. g++) and have downloaded CxxTest.
You can download CxxTest from [here](https://sourceforge.net/projects/cxxtest/files/cxxtest/)

Once you have CxxTest installed you can unzip to a suitable directory on your system.

On the University PCs g++ is **not** installed by default! In order to get it you can launch codeblocks from the apps anywhere system, and then you will find the g++ in the directory: C:\Program Files (x86)\CodeBlocks\MinGW\bin\g++.exe

### Creating your first Cxx Test Suite

Unit testing involes testing your own code. I.e. you should not be testing any API or library calls. You will need to seperate your source code from your API calls. I suggest creating a seperate class with methods for your business logic code (i.e. any code **not** invloved wih input or output API calls).

So in my example I have Maths.h and Maths.cpp which contains my business logic (a simple add function). For yours, you may be calculating a moving average etc.
Then you will need to write a test suite for CxxTest to work, let's call it - TestSuiteCXX.h
You can see an example for the structure of a Cxx test suite [here](http://cxxtest.com/guide.html).

We can run the test suite from command line with the following 3 statements:

cxxtestgen --error-printer -o runner.cpp MyTestSuite1.h

g++ -o runner -I$CXXTEST runner.cpp

./runner

This will give you output such as:
Running cxxtest tests (1 test).OK!

Now, you **will** need to modify these commands based on the your project paths on the system you use and the CxxTest and g++ install directories etc.
On my system (Uni PC) the commands look like:

H:\_Lecturer\302CEM\cxxtest-4.4\cxxtest-4.4\bin\cxxtestgen --error-printer -o runner.cpp TestSuiteCxx.h

"C:\Program Files (x86)\CodeBlocks\MinGW\bin\g++" -o runner -IH:\_Lecturer\302CEM\cxxtest-4.4\cxxtest-4.4 runner.cpp Maths.cpp

.\runner

Note on Uni PCs I manged to get this working through the default windows command line - cmd.exe. Note Windows powershell.exe did not work for me!


Once you have this working from command line you can then investigate automated testing via creating you own custom build scripts.

The build process including tests can also be automated (i.e. automated testing) via a build system e.g. Makefiles, an example is here:
https://emou.wordpress.com/2009/10/02/unit-testing-in-c-using-cxxtest/


## Switching from the Arduino IDE to using VSCode

@@ -0,0 +1,24 @@
// TestSuiteCxx.h
// This file contains our Cxx Test Suite which is defining our tests for our code in Maths.cpp

#include <cxxtest/TestSuite.h>
#include "Maths.h"

class TestSuiteCxx : public CxxTest::TestSuite
{
public:
void testAddition1(void)
{
Maths myObject;
TS_ASSERT(myObject.add(1, 1) > 1);
TS_ASSERT_EQUALS(myObject.add(1, 1), 2);
}

void testAddition2(void)
{
Maths myObject;
TS_TRACE("Starting addition2 test");
TS_ASSERT_EQUALS(myObject.add(2, 2), 5); // this will fail our test because our test has errors
TS_TRACE("Finishing addition2 test");
}
};
@@ -0,0 +1,43 @@
/* Generated file, do not edit */

#ifndef CXXTEST_RUNNING
#define CXXTEST_RUNNING
#endif

#define _CXXTEST_HAVE_STD
#include <cxxtest/TestListener.h>
#include <cxxtest/TestTracker.h>
#include <cxxtest/TestRunner.h>
#include <cxxtest/RealDescriptions.h>
#include <cxxtest/TestMain.h>
#include <cxxtest/ErrorPrinter.h>

int main( int argc, char *argv[] ) {
int status;
CxxTest::ErrorPrinter tmp;
CxxTest::RealWorldDescription::_worldName = "cxxtest";
status = CxxTest::Main< CxxTest::ErrorPrinter >( tmp, argc, argv );
return status;
}
bool suite_TestSuiteCxx_init = false;
#include "TestSuiteCxx.h"

static TestSuiteCxx suite_TestSuiteCxx;

static CxxTest::List Tests_TestSuiteCxx = { 0, 0 };
CxxTest::StaticSuiteDescription suiteDescription_TestSuiteCxx( "TestSuiteCxx.h", 7, "TestSuiteCxx", suite_TestSuiteCxx, Tests_TestSuiteCxx );

static class TestDescription_suite_TestSuiteCxx_testAddition1 : public CxxTest::RealTestDescription {
public:
TestDescription_suite_TestSuiteCxx_testAddition1() : CxxTest::RealTestDescription( Tests_TestSuiteCxx, suiteDescription_TestSuiteCxx, 10, "testAddition1" ) {}
void runTest() { suite_TestSuiteCxx.testAddition1(); }
} testDescription_suite_TestSuiteCxx_testAddition1;

static class TestDescription_suite_TestSuiteCxx_testAddition2 : public CxxTest::RealTestDescription {
public:
TestDescription_suite_TestSuiteCxx_testAddition2() : CxxTest::RealTestDescription( Tests_TestSuiteCxx, suiteDescription_TestSuiteCxx, 17, "testAddition2" ) {}
void runTest() { suite_TestSuiteCxx.testAddition2(); }
} testDescription_suite_TestSuiteCxx_testAddition2;

#include <cxxtest/Root.cpp>
const char* CxxTest::RealWorldDescription::_worldName = "cxxtest";
Binary file not shown.
@@ -8,7 +8,7 @@ You have been placed in multi-skilled teams and will be working in these through
Tuesday 09:00-11:00 and Wednesday 11:00-13:00

1. Thomas Bassett
2. Daniel Steven Beglin
2. Marius Gamulea
3. Nikhil Dassor
4. Tahir Saddique Gulzed
5. Jabor Mubarak J M Al-Ali
@@ -124,6 +124,7 @@ Tuesday 11:00-13:00 and Friday 09:00-11:00
6. Jessica Pearson
7. Erin Rai
8. Jaewoong Yu
9. Daniel Steven Beglin

## 🐰 Team Rabbit

0 comments on commit 2d262c7

Please sign in to comment.