joechastain
02/10/2023, 4:55 PMexecute
call of the handler?Adam Cameron
0
as a major version I don't know how to interpret "handler" or the execution thereof?Adam Cameron
joechastain
02/10/2023, 5:41 PMAdam Cameron
Adam Cameron
joechastain
02/10/2023, 6:01 PMcoldbox.system.testing.BaseModelTest
. Then in beforeAll()
I do something like calculatorService = createMock( "models.CalculatorService" );
for the model under test. Then calculatorData = createEmptyMock( "models.CalculatorData" );
which is where a sql query resides and I, of course, don't want to hit the actual database in a unit test. To mock the DI of the calculatorData into the service calculatorService.$property( propertyName="calculatorData", mock=calculatorData );
Then in the test itself I can use querySim()
to simulate a query and use that to mock the method in the data layer calculatorData.$( "getData", querySimData );
Then I simply run the method in the calculatorService that I want to test that calls the mocked data layer. All this works great.
However, now I want to do something similar in a Coldbox handler, which is typically where an integration test would be used (or so I understand). I've had some success with handlers that have form data passed in. I've been doing something like getRequestContext().setValue( "employeeName", "Joe Chastain" );
which sets the value in the rc scope for a variable named employeeName
. Then var event = execute( event="main.calculate", renderResults=true );
to execute the handler. Then I can check the rendered results for various things. Again, this works great.
But now I want to be able to mock objects that the handler calls. This is different from the unit test because instead of creating a mock object to test, the execute
method is called. I've not yet been able to figure out how to set the mocked object as a property of the handler because of this difference.joechastain
02/10/2023, 6:02 PMRight so it's a "CB integration with TB" question.
I won't be able to help you. I know f-all about CBUnderstood. Thanks for chiming in anyway. 🙂
joechastain
02/10/2023, 6:08 PMAdam Cameron
Adam Cameron
Adam Cameron
Adam Cameron
joechastain
02/10/2023, 7:04 PMjoechastain
02/10/2023, 7:12 PMBTW: pleased to see someone who's actually comfortable with testing and mocking and stuff in the CFML community.Thanks. I'm just getting started and know I have a ton more to learn. I'm pretty sure I'll be going to Into the Box in May and attending Brad's full day 'TestBox' workshop.
Adam Cameron
joechastain
02/10/2023, 7:19 PMAdam Cameron