Skip to content
This repository has been archived by the owner on Oct 31, 2019. It is now read-only.

Latest commit

 

History

History
63 lines (39 loc) · 2.28 KB

install.md

File metadata and controls

63 lines (39 loc) · 2.28 KB

Running unittests

To run unittests a Test enviroment is needed.

  • Fhem installation in /opt/fhem
  • Experience in perl
  • Knowledge of Test::More

Requirements for 98_UnitTest.pm

You should not run the UnitTests on a productive used fhem installation.

  1. install required test modules via cpan Test::Device::SerialPort cpan Mock::Sub and cpan Test::More
    On Systems with low memory, use cpanm for installing the packages.

  2. 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

Requirements for test-runner.sh

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.

Writing my first unittest

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.