Lab::Measurement::Developer::Testing - Using mock instruments for testing
version 3.691
You can monitor all method calls to the interface defined in Connection.pm. To do this, you use a Log connection:
Log
my $instr = Instrument('Agilent34410A', { connection_type => 'LinuxGPIB::Log', logfile => 'mylogfile.yml' gpib_address => 17});
This will log all calls to the connection's methods:
This information is then stored in mylogfile.yml. The contents of this file might look like this:
mylogfile.yml
--- id: 0 method: is_blocked retval: 0 --- command: FUNCTION 'volt:ac' id: 1 method: Write retval: 1 --- id: 2 method: is_blocked retval: 0 --- command: FUNCTION? id: 3 method: Query retval: '"VOLT:AC"' --- command: '*RST' id: 4 method: Write retval: 1
For each call, we log the method name and the return value. Some methods receive additional parameters, like the command sent to the instrument.
Mock instruments are the main ingredient when building unit tests for the Lab::Measurement package.
Using the output from a Log connection, it is possible to rerun a measurement script without using the physical instrument.
This is done by providing a previously recorded log file to the Mock connection:
Mock
my $instr = Instrument('Agilent34410A', { connection_type => 'Mock', logfile => 'mylogfile.yml'});
The Mock connection will croak, if the calls to it deviate from the provided log file.
This software is copyright (c) 2019 by the Lab::Measurement team; in detail:
Copyright 2016 Simon Reinhardt 2017 Andreas K. Huettel 2018 Simon Reinhardt
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.
To install Lab::Measurement, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Lab::Measurement
CPAN shell
perl -MCPAN -e shell install Lab::Measurement
For more information on module installation, please visit the detailed CPAN module installation guide.