Question-and-Answer Resource for the Building Energy Modeling Community
Get started with the Help page
Ask Your Question

Revision history [back]

Assuming you are starting from the template measure test file that comes with a new measure, while most tests expect to be successful, one test named test_bad_argument_values feeds in an invalid string argument, specifically an empty string a where a string is required'.

You can delete this test, or make sure you are feeding in an empty string to one of your two arguments. The GUI might protect against this specific type of bad input, but if for example you had a double argument and you want it to be positive, you can add something like this to your measure, and have a test to confirm it gracefully failed, vs. running and using an invalid double later on.

if my_arg <= 0 then
  runner.registerError("Please enter a positive value")
  return false
end

The return false in the measure forces the measure to stop and returns a value of false vs. true that would normally be expected.

If you have not looked at it yet, the OpenStudio Measure Writing Guide can be a very good resource.

Assuming you are starting from the template measure test file that comes with a new measure, while most tests expect to be successful, one test named test_bad_argument_values feeds in an invalid string argument, specifically an empty string a where a string is required'.required.

You can delete this test, or make sure you are feeding in an empty string to one of your two arguments. The GUI might protect against this specific type of bad input, but if for example you had a double argument and you want it to be positive, you can add something like this to your measure, and have a test to confirm it gracefully failed, vs. running and using an invalid double later on.on. You don't for example want the measure to try set a field for a model object to an invalid value. This kind of error handling, and testing of error handling is useful to make the measure more robust.

if my_arg <= 0 then
  runner.registerError("Please enter a positive value")
  return false
end

The return false in the measure forces the measure to stop and returns a value of false vs. true that would normally be expected.

If you have not looked at it yet, the OpenStudio Measure Writing Guide can be a very good resource.

resource.