NAME
Lab::Measurement::Developer::Testing - Using mock instruments for testing
VERSION
version 3.641
Using mock instruments for testing.
Connection logging.
You can monitor all method calls to the interface defined in Connection.pm. To do this, you use a Log
connection:
my $instr = Instrument('Agilent34410A', {
connection_type => 'LinuxGPIB::Log',
logfile => 'mylogfile.yml'
gpib_address => 17});
This will log all calls to the connection's methods:
- Clear
- Write
- Read
- Query
- BrutalRead
- LongQuery
- BrutalQuery
- timeout
- block_connection
- unblock_connection
- is_blocked
This information is then stored in mylogfile.yml
. The contents of this file might look like this:
---
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.
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:
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.
COPYRIGHT AND LICENSE
This software is copyright (c) 2018 by the Lab::Measurement team; in detail:
Copyright 2016 Simon Reinhardt
2017 Andreas K. Huettel
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.