Skip to content

Commit 70ca176

Browse files
author
davert
committed
new CI post
1 parent 66ad0f4 commit 70ca176

File tree

1 file changed

+71
-0
lines changed

1 file changed

+71
-0
lines changed
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
---
2+
layout: post
3+
title: "Continuous Integration In Practice: Codeception, Jenkins, Xvfb"
4+
date: 2013-05-24 22:03:50
5+
---
6+
7+
*Another blogpost from Ragazzo containing some practical information. If you ever wanted to ask how to set up a Continuous Integration with Codeception, you can read it here. He shares some useful tips you should be aware of.*
8+
9+
It is very good to automate maximum of the things you can. Once we automated testing process, build should be automated too. I use [Jenkins](http://jenkins-ci.org/) as my primary continuous integration server. It can be installed and executed on all popular operating systems with Java enabled.
10+
11+
12+
<img src="http://jenkins-ci.org/sites/default/files/images/headshot.png" style="float: right;" />
13+
14+
15+
As for PHPUnit I use JUnit format for error reports and some **Jenkins** plugins to make it work with Code Coverage. For **Behat** and **Codeception** I also use JUnit output log format and [Jenkins PHPUnit Plugin](http://jenkins-php.org/).
16+
17+
Thus, my application have 4 jobs in Jenkins they named in that way:
18+
19+
* MyProject_Testing_Unit # via phpunit
20+
* MyProject_Testing_Func # via behat
21+
* MyProject_Testing_Func_Web # codeception functional
22+
* MyProject_Testing_Accep_Web # codeception acceptance
23+
24+
And of course one job for bulding packages for demo and for developer:
25+
26+
* MyProject_Build_Dist
27+
28+
I scheduled jobs to run one by one so the first goes "Unit", then it triggers "Func", then "Func" triggers "Func_Web" and so on. "Build" is not triggered automatically, I start it by myself.
29+
30+
#### COnfiguring Builds
31+
32+
Lets pay attention on two of them that include Codeception. I'm using **Ant** build tool to execute them.
33+
Bascially for JUnit output you need nothing more then running codeception with `--xml` option. Like this:
34+
35+
{% highlight bash %}
36+
codecept.phar --xml run functional
37+
{% endhighlight %}
38+
39+
This will produce the `report.xml` file in `tests/_log` directory, which will be analyzed by Jenkins. In my Ant task I'm also clearing a _log directory before running tests.
40+
41+
{% highlight xml %}
42+
<project name="{SomeMyProject}_Testing_Func_Web" default="build" basedir=".">
43+
<target name="clean">
44+
<delete dir="${basedir}/build/src/protected/tests/codeception/tests/_log" includes="**/*" />
45+
</target>
46+
<target name="codeception">
47+
<exec dir="${basedir}/build/src/protected/tests/codeception" executable="php" failonerror="true">
48+
<arg line="codecept.phar --xml run functional" />
49+
</exec>
50+
</target>
51+
<target name="build" depends="clean, codeception"/>
52+
</project>
53+
{% endhighlight %}
54+
55+
Also you may want to add the `--html` option for execution. That would produce a readable HTML report, that you can show to your boss. You will need [HTML Publisher Plugin](https://wiki.jenkins-ci.org/display/JENKINS/HTML+Publisher+Plugin) to display it in Jenkins web interface.
56+
57+
### Using Selenium2 and Xvfb
58+
59+
To run acceptance web tests correctly on server you don't need to install desktop environment like Gnome or XFCE just to launch a browser. Better to use Virtual Framebuffer [Xvfb](http://en.wikipedia.org/wiki/Xvfb) for running Selenium tests without showing them on screen.
60+
61+
You need to install Xfvb and then run Selenium2 with this options:
62+
63+
{% highlight bash %}
64+
export DISPLAY=":1" && java -jar selenium-server-standalone.jar
65+
{% endhighlight %}
66+
67+
Then start your Codeception acceptance tests as usual. By the way, I suggest you to use [this Xvfb init script](https://gist.github.com/jterrace/2911875) in Ubuntu.
68+
69+
*There is nothing hard in setting up Jenkins. You can use Codeception with it or in any other CI server. If you already did that, please share your experience with community. We really need more personal experiences and blogposts from the community. Documentation can't cover all use cases, that's why your thought are much appreciated. If you don't have a blog we can publish your blogpost here.
70+
71+
P.S. Just to mention, If you are using **Bamboo** CI server, pls enable the `--no-exit` option to run tests correctly.*

0 commit comments

Comments
 (0)