To run unittests a Test enviroment is needed.
- Fhem installation in /opt/fhem
- Experience in perl
- Knowledge of Test::More
You should not run the UnitTests on a productive used fhem installation.
-
install required test modules via
cpan Test::Device::SerialPort
cpan Mock::Sub
andcpan Test::More
On Systems with low memory, use cpanm for installing the packages. -
You can use make for running the tests. There is a makefile which will prepare your fhem installation for running the tests.
- stop any running fhem instance
- copy the module into the fhem directory /opt/fhem/FHEM
- copy a minimal config file for fhem fhem_ut.cfg and start fhem with this configfile.
- run the tests in the tests directory. They must be named -definition.txt
- cleans up logfiles
- stop fhem
Now you can start defining a unittest
cd /opt/fhem
perl fhem.pl fhem.cfg
You can run tests from the commandline. Make will do this for you automatic
Currently test-runner searches logfiles in /opt/fhem. So you can install your test instance of fhem into a separate directoy but you must link the logfile to /opt/fhem
Unit Testfiles are searched in the directory test.
If you call test-runer.sh my_test_1
then this will try to load a file test/my_test_1-definition.
Define a new test with
defmod my_Test_1 UnitTest dummyDuino ({} )
Now you have a placeholder for defining your code. Open the DEF from this device an put any perl code inside the {} brackets.
Note: the Name dummyDuino must be the name of a existing definition you want to run tests on. If you startet fhem with the provided minimal fhem-ut.cfg
, then there is no Device of type SIGNALduino named dummyDuino. You can also use the Device WEB or global.
In your testcode you can run any perl command.
Additionally there are a few variables provided
$hash = the hash of the UnitTest Definition $name = The Name of the UnitTest Definition $target = The Name of the provided Targetdevice which is under test. Provided in DEF from this UnitTest device. In our example dummyDuino. $targetHash = Hash from the Targetdevice which is under test.