Hi, I am fairly new to TestBox and Coldbox, but I...
# testing
n
Hi, I am fairly new to TestBox and Coldbox, but I run into an issue which I don’t understand. I have written a BDD test which tests some Coldbox code. The Coldbox code makes use of a Service. Services need a reinit when you change some code, so every time I run my test, I need the Coldbox application to reinit. The strange thing is, when I run my test on the commandbox cli, a reinit takes place automatically since every change in my Service is visible immediately. However when I run the same test in the browser, a reinit does not take place. I have to do a reinit manually first and then I can run my test in the browser. The URL called from the commandbox CLI is: http://myhost/tests/runner.cfm?&labels=mytest&recurse=true&reporter=json&verbose=false The URL called from the browser is: http://myhost/tests/specs/integration/forms/StoreFormDataTest.cfc?method=runRemote Both run the exact same test, but the first one does a reinit and the second one does not. How can I get the test from the browser to initiate a reinit before running the test?
a
I'm unfamiliar with ColdBox, but I'd put a
<cfthrow>
within the
reinit
method and have a look at the CFML context to see how/where it's being called. That should give you an idea. That said, I'd be wondering why you need yer framework stuff loaded to run a test. Could be legit depending on what yer testing, but it would def raise a yellow flag with me.
w
If you are calling some REST action e.g POST https://somesite/item in an integration test you need coldbox to get a response. I was wondering if there’s something bad about that. In many testbox examples (in presentations and ortus workshops) they are testing in this manner. I understand you don’t need a framework for ALL integration tests. Just trying to understand what’s wrong with it. I can mention a few things myself: cookies, coldbox flash storage, sessions interfering, all things which should be mocked if testing this way.
a
I'd probably refer to any tests that are actually going end-to-end through client request, routing, controller, model, storage, view "End to End tests" or "acceptance tests". In some integration tests it'd fine, depending what integration (how your code integrates with someone else's code) yer testing. If you were testing how yer code interacts with the framework: you'll need to load the framework, obvs. Although for like adapter-level integration tests I'd just want to instantiate the adapter by hand, and not involve anything unnecessary. Rule of thumb, a test should use only whichever support services are needed for the SUT to operate for the given style of test. Another rule of thumb: each external support service one needs to exercise the test should raise another flag. Raised flags might be fine. But they should be assessed. I would say if yer unit tests need to have the framework running, either yer app or the framework is poorly designed.
w
I am 100% sure Niek is referring to integration tests here and not unit tests, e.g. calling some route and evaluate the response in a coldbox REST application. I guess you would call this end to end, and ortus would call the same tests integration tests. The weird thing here is we both have a similar setup and in my setup I don’t have to reload the services and in his setup he has. That’s when testing with the HTML runner. When testing from commandbox a reinit is not necessary.