You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardexpand all lines: digging-deeper/recipes/application-templates.md
+2-2
Original file line number
Diff line number
Diff line change
@@ -6,10 +6,10 @@ We have a Github organization called [coldbox-templates](https://github.com/cold
6
6
7
7
The `coldbox create app` command has integration to our application templates via the `skeleton` argument. This can be the name of each of the templates in our repositories or you can use the following alternatives:
8
8
9
-
* Name of template in our organization: `advanced,simple,super-simple,etc`
9
+
* Name of template in our organization: `advanced,simple,super-simple,rest, rest-hmvc, vuejs, etc`
10
10
* A name of a ForgeBox entry: `cbtemplate-advanced-script,cbtemplate-simple`
11
11
* A Github shortcut: `github-username/repo`
12
-
* An HTTP/S URL to a zip file containing a template: \`[http://myapptemplates.com/template.zip](http://myapptemplates.com/template.zip)
12
+
* An HTTP/S URL to a zip file containing a template: [http://myapptemplates.com/template.zip](http://myapptemplates.com/template.zip)
13
13
* A folder containing a template: `/opt/shared/templates/my-template`
14
14
* A zip file containing the template: `/opt/shared/templates/my-template.zip`
Copy file name to clipboardexpand all lines: testing/testing-coldbox-applications/README.md
+15-5
Original file line number
Diff line number
Diff line change
@@ -1,14 +1,18 @@
1
1
# Testing ColdBox Applications
2
2
3
-
One of the best things you can do when you develop software applications is TEST! I know nobody likes it, but hey, you need to do it right? With the advocation of frameworks today, you get all these great tools to build your software applications, but how do you test your framework code. ColdBox has revolutionized testing MVC and framework code, since you can unit test your event handlers, interceptors, model objects and even do integration testing and test your entire application with no browser at all.
3
+
One of the best things you can do when you develop software applications is TEST! I know nobody likes it, but hey, you need to do it right? With the advocation of frameworks today, you get all these great tools to build your software applications, but how do you test your framework code. ColdBox has revolutionized testing HMVC and framework code, since you can unit test your event handlers, interceptors, model objects and even do **integration testing and true BDD \(Behavior Driven Development\)** and test your entire application with no browser at all.
4
4
5
5
ColdBox has already all the hooks in place to provide Behavior and Test Driven Development via [TestBox](http://www.ortussolutions.com/products/testbox) and mocking/stubbing capabilities via MockBox.
6
6
7
-
> TestBox is a testing framework for ColdFusion \(CFML\) that is based on BDD \(Behavior Driven Development\) for providing a clean obvious syntax for writing tests. It also includes MockBox for mocking and stubbing.
7
+
{% hint style="info" %}
8
+
**TestBox** is a testing framework for ColdFusion \(CFML\) that is based on BDD \(Behavior Driven Development\) for providing a clean obvious syntax for writing tests. It also includes MockBox for mocking and stubbing.
9
+
10
+
**TestBox is included with all ColdBox templates.**
11
+
{% endhint %}
8
12
9
13
## Installing TestBox
10
14
11
-
So let's get started by opening a CommandBox prompt \(`box`\) in your application root and installing TestBox.
15
+
TestBox already comes defined in the `box.json` of all ColdBox application templates. However, if you have a custom ColdBox app or a custom template, then you can easily install it via CommandBox:
12
16
13
17
```bash
14
18
// stable
@@ -18,7 +22,9 @@ install testbox --saveDev
18
22
install testbox@be --saveDev
19
23
```
20
24
21
-
> **Info** The `--saveDev` flag tells CommandBox to save TestBox locally only for testing purposes as it will not be used to send TestBox for production \([http://commandbox.ortusbooks.com/content/packages/dependencies.html](http://commandbox.ortusbooks.com/content/packages/dependencies.html)\)
25
+
{% hint style="info" %}
26
+
The --saveDev flag tells CommandBox to save TestBox locally only for testing purposes as it will not be used to send TestBox for production \([http://commandbox.ortusbooks.com/content/packages/dependencies.html](http://commandbox.ortusbooks.com/content/packages/dependencies.html)\)
27
+
{% endhint %}
22
28
23
29
Please also note that CommandBox ships with tons of commands for interacting with TestBox and ColdBox testing classes. You can explore them by issuing the following commands or viewing the latest CommandBox API Docs \([http://apidocs.ortussolutions.com/commandbox/current](http://apidocs.ortussolutions.com/commandbox/current)\)
24
30
@@ -32,6 +38,9 @@ testbox create help
32
38
# run tests
33
39
testbox run help
34
40
41
+
# Watch your files and execute the tests if they change
42
+
testbox watch
43
+
35
44
# coldbox creation help
36
45
coldbox create help
37
46
```
@@ -47,11 +56,12 @@ It might be that testing is tedious and takes time to get into the flow of Behav
47
56
* Encourages refactoring to produce testable code
48
57
* Testing is all about behavior and expectations
49
58
59
+
**Our recommendation is to do BDD and integration testing first. Unit testing is important but it is more important to verify that your requirements are met.**
Copy file name to clipboardexpand all lines: testing/testing-coldbox-applications/coldbox-testing-classes.md
+4-4
Original file line number
Diff line number
Diff line change
@@ -6,8 +6,8 @@ Before we begin our adventures in testing, let's review what classes does ColdBo
6
6
7
7
From that super class we have our own ColdBox `BaseTestCase` which is our base class for any testing in ColdBox and the class used for Integration Testing. We then spawn several child classes for targeted testing of different objects in your ColdBox applications:
8
8
9
-
*`BaseTestCase` - Used for Integration Testing
10
-
*`BaseModelTest` - Used for model object testing
11
-
*`BaseInterceptorTest` - Used for interceptor testing
12
-
*`BaseHandlerTest` - Used for isolated handler testing
9
+
*`BaseTestCase` - Used for **Integration Testing**
10
+
*`BaseModelTest` - Used for model object unit testing
11
+
*`BaseInterceptorTest` - Used for interceptor unit testing
12
+
*`BaseHandlerTest` - Used for isolated handler unit testing
We will begin our adventure with integration testing. Integration testing allows you to test a real life request to your application without using a browser. Your test bundle CFC will load a new virtual application for you to test each specification under it; all aspects of your application are loaded: caching, dependency injection, AOP, etc. Then you can target an event to test and verify its behavior accordingly. First of all, these type of tests go in your `integration` folder of your test harness or in the specific module folder if you are testing modules.
We will explain later the life-cycle methods and the `run()` method where you will be writing your specs.
47
+
48
+
> **Hint** Please refer to our BDD primer to start: [http://testbox.ortusbooks.com/content/primers/bdd/index.html](http://testbox.ortusbooks.com/content/primers/bdd/index.html)
49
+
50
+
### CommandBox Generation
51
+
52
+
Also remember that you can use CommandBox to generate integration tests with a few simple commands:
> **Info** Please also note that whenever you create a handler, interceptor or model with CommandBox it will automatically create the integration or unit test for you.
The base test cases all inherit from TestBox so here are a few of the common methods you can find in every test bundle CFC \([http://testbox.ortusbooks.com/content/test\_bundles/index.html](http://testbox.ortusbooks.com/content/test_bundles/index.html)\):
Copy file name to clipboardexpand all lines: testing/testing-coldbox-applications/integration-testing/handler-returning-results.md
+25
Original file line number
Diff line number
Diff line change
@@ -2,3 +2,28 @@
2
2
3
3
4
4
5
+
## Handler Returning Results
6
+
7
+
If you have written event handlers that actually return data, then you will have to get the values from the request collection. The following are the keys created for you in the request collection.
8
+
9
+
| Key | Description |
10
+
| :--- | :--- |
11
+
|`cbox_handler_results`| The value returned from the event handler method. This key will NOT be created if the handler does not return any data. |
12
+
13
+
**The handler**\(`main.cfc`\)
14
+
15
+
```text
16
+
function list(event,rc,prc){
17
+
return "Hola Luis";
18
+
}
19
+
```
20
+
21
+
**The spec**
22
+
23
+
```text
24
+
it( "+homepage renders", function(){
25
+
var event = execute( event="main.list", renderResults=true );
ColdBox testing leverages TestBox's testing life-cycle events \([http://testbox.ortusbooks.com/content/life-cycle\_methods/index.html](http://testbox.ortusbooks.com/content/life-cycle_methods/index.html)\) in order to prepare the virtual ColdBox application, request context and then destroy it. For performance, a virtual application is loaded for all test cases contained within a test bundle CFC via the `beforeAll()` and destroyed under `afterAll()`.
6
+
7
+
```text
8
+
function beforeAll(){
9
+
super.beforeAll();
10
+
// do your own stuff here
11
+
}
12
+
13
+
function afterAll(){
14
+
// do your own stuff here
15
+
super.afterAll();
16
+
}
17
+
```
18
+
19
+
> **Important** If you override any of these methods and do not funnel the super call, then you might get cached or unexpected results.
20
+
21
+
### Improving Performance: Unloading ColdBox
22
+
23
+
The default for integration testing is that the virtual ColdBox application will be destroyed or unloaded in each test. To keep the virtual application accross requests you will need to use the `unloadColdBox=false` annotation or the `this.unloadColdBox=false` setting in your `beforeAll()` method. This will stop the testing classes from destroying ColdBox and improving performance.
Copy file name to clipboardexpand all lines: testing/testing-coldbox-applications/integration-testing/rendering-results.md
+22
Original file line number
Diff line number
Diff line change
@@ -2,3 +2,25 @@
2
2
3
3
4
4
5
+
## Rendering Results
6
+
7
+
The `execute()` method has an argument called `renderResults` which defaults to **false**. If you pass in **true** then ColdBox will go through the normal rendering procedures and save the results in a request collection variable called: `cbox_rendered_content` and expose to you a method in the request context called `getRenderedContent()`. It will even work with `renderData()` or if you are returning RESTful information. Then you can easily assert what the content would have been for an event.
8
+
9
+
```text
10
+
it( "can render users", function(){
11
+
var event = execute( event="rest.api.users", renderResults=true );
In testing mode, the ColdBox request context `event` object has a convenience method called `getRenderedContent()` that will give you the rendered content instead of you going directly to the request context and finding the `cbox_rendered_content` variable.
19
+
20
+
```text
21
+
it( "can render users", function(){
22
+
var event = execute( event="rest.api.users", renderResults=true );
|`appMapping`| string | false |`/`| The application mapping of the ColdBox application to test. By defaults it maps to the root. Extermely important this mapping is a slash notation that points to the root of the ColdBox application to test. |
8
+
|`configMapping`| string | false |`{appMapping}/config/Coldbox.cfc`| The configuration file to load for this test, which by convention uses the same configuration as the application uses. This is a dot notation path to a configuration CFC. |
9
+
|`coldboxAppKey`| string | false |`cbController`| The named key of the ColdBox controller that will be placed in application scope for you to simulate the ColdBox application. Used mostly on advanced testing cases where you have altered the default application key. |
10
+
|`loadColdBox`| boolean | false | true | By default the base test case will load the virtual application into the `application`scope so all specs can execute |
11
+
|`unloadColdBox`| boolean | false | true | The base test case will unload the virtual application from the `application` scope after all specs have executed. |
Here is a spec written for you. Please note that in the `beforeEach()` life-cycle method you need to execute the `setup()` method will will setup a new ColdBox request for each spec you run.
0 commit comments