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

Expected: "Fail" Actual: "Success" running template _test.rb

asked 2019-05-03 09:39:12 -0500

Tate's avatar

Hello, I'm new to using OpenStudio and am trying to write my own measure for the first time. So far I'm using the measure template produced by open studio, and have only modified the arguments section (I've copied that in at the bottom). When I run the _test.rb template def test_bad_arguments section, I get a failure:

1) Failure: OccupancyTestTest#test_bad_argument_values [C:/.../occupancy_test_test.rb:68]: Expected: "Fail" Actual: "Success"

My questions are What exactly is this section testing for? Why is it producing a Failure?

I'm new so please tell me if I've made a very obvious error!

Kind thanks.

def arguments(model)

args =
# the name of the file to import to the model
file_name = OpenStudio::Measure::OSArgument.makeStringArgument("file_name", true)
file_name.setDisplayName('CSV File Name')
file_name.setDescription('This name will be used as the name of the CSV file to load.')
args << file_name

sched_name = OpenStudio::Measure::OSArgument.makeStringArgument("sched_name", true)
sched_name.setDisplayName('Ground Truth Schedule')
sched_name.setDescription('Ground Truth Schedule from CC Occupancy Data')
sched_name.setDefaultValue('Ground Truth Schedule')
args << sched_name
return args


edit retag flag offensive close merge delete


What is on line 68 of occupancy_test_test.rb?

shorowit's avatar shorowit  ( 2019-05-03 11:15:28 -0500 )edit

Hi, Line 68 is: assert_equal('Fail', result.value.valueName)

Tate's avatar Tate  ( 2019-05-07 05:15:09 -0500 )edit

1 Answer

Sort by ยป oldest newest most voted

answered 2019-05-03 13:54:45 -0500

updated 2019-05-03 13:57:54 -0500

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

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.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer


Question Tools



Asked: 2019-05-03 09:39:12 -0500

Seen: 106 times

Last updated: May 03 '19