Writing an integration test with TestBox, I want t...
# testing
b
Writing an integration test with TestBox, I want to completely mock an AWS S3 service (.cfc file in the app that reaches out to S3). Is this the right way to do it?
mockBox.createStub(extends="path.to.my.s3service");
That will create a fake S3 service that mirrors the interface etc of my service but not actually do anything, right? Do I need to call init() on that as well to instantiate it?
Hmm it seems to be actually trying to do stuff when I initialize the s3 service mock as created above. Does createstub not just mock out all the functions and properties so they don't do anything like I'm thinking? I'm using it like :
Copy code
application.mockS3 = mockBox.createStub(extends="path.to.my.service").init(...some props);
j
👀 1
b
Thx. I saw that, but when I read it wipes out signatures and you had to specify implementation, I thought that meant I'd have to set it up more, but let me just use that and see what happens
j
Yes, most of the other methods are going to try to instantiate the object completely before creating the stub/mock - especially if there are things in the pseudo-constructor
b
Does that mean that with
createStub()
it will instantiate the class that is set to
extends
passed in automatically? (I notice different behavior when I append
.init()
to createStub vs. leave it off, so not sure if it's already doing that)
a
there is
createMock
as well which preserves the signatures and is what I use most of the time
👀 1
neither
createMock
or
createEmptyMock
call the
init
method but you'll get back the object (either with methods or without)
👍 1
b
Got it, ty. Is it recommended to call
.init()
or new up the mocked object after using createMock etc.? Or does it matter? Use case is passing the service or mocked component into another component under test (the mock/test double is a dependency the sut requires).
a
You don't need to. Remember these are mocks not the subject under test (the cfc) so they just need to fulfil the dependancies of the subject under test
b
Roger. Thank you for the clarification 🙏
🫡 1