A video session on "Intro to MySQL master slave Replication". Hope you enjoy it :)
code prettify
Tuesday, 26 April 2016
Tuesday, 12 April 2016
Developing a To-Do application using TDD approach using QUnit as the testing framework
I recently tried my hands at TDD to develop a basic ToDo app using QUnit as the testing framework.
To run and see the results of tests, refer below links:
Unit test results
Integration / Functional test results
Hope this helps in learning :)
Here is the link to the application demo.
I have written both unit and integration / functional tests while developing this app. The source code can be checked here.
To run and see the results of tests, refer below links:
Unit test results
Integration / Functional test results
Hope this helps in learning :)
Labels:
app,
functional,
integration,
jquery,
qunit,
TDD,
tests,
todo,
unit
Monday, 11 April 2016
Video Tutorial on Network Throttling tool provided by Google Chrome Developer tools
Network Throttling tool provided by Google Chrome Developer tools
In this video we will be seeing how this tool helps us to test your application at different network speeds, thus giving us info and insight as to how users having different speeds of internet use our application and the challenges they face and how the performance can be improved and how the application can be made more usable in such cases.
Friday, 8 April 2016
Interesting article on importance of coding and testing
A very interesting article on testing and coding illustrating many simple tips, important points:
- why one should test and code
- what one should test
- how and what kind of testing one can provide
- what one should not test
- how important testing is
- and others
If you are new to testing, it is a good place to start. Overall as the title of the article says "Why and how testing can make you happier", so it is time to be happy :D
Interesting read it makes. Hope you enjoy it too as I have :)
http://mikbe.com/code/testing/dx/2016/03/11/why-and-how-testing-can-make-you-happier.html
- why one should test and code
- what one should test
- how and what kind of testing one can provide
- what one should not test
- how important testing is
- and others
If you are new to testing, it is a good place to start. Overall as the title of the article says "Why and how testing can make you happier", so it is time to be happy :D
Interesting read it makes. Hope you enjoy it too as I have :)
http://mikbe.com/code/testing/dx/2016/03/11/why-and-how-testing-can-make-you-happier.html
Thursday, 31 March 2016
Lorem ipsum content for html
If you want some dummy html content for test purpose like form, paragraph or list content then you can use content from http://html-ipsum.com/
Sunday, 27 March 2016
Testing APIs in CodeIgniter 2.x using phpunit and Guzzle Http client
Sometimes we have apis implemented in our application and there are different levels at which these can be tested.
1. Unit tested at model level to check the logic is working fine
2. Tested at API call level to ascertain whether all the apis as expected are working and are returning data as expected.
Today, we will be learning how to test APIs in CodeIgniter 2.x version using phpunit and Guzzle Http client.
Basically Guzzle Http client is a client used to make http client requests.
Ref: https://github.com/guzzle/guzzle
"Guzzle is a PHP HTTP client that makes it easy to send HTTP requests and trivial to integrate with web services."
We will basically be creating an API for a blog so as to get blog posts and add blog post. When testing APIs, we are basically testing the output format, expected fields in the output and their data type and value if needed.
Sample code can be found at git repository here: https://github.com/satejkumar/CodeIgniter_API_Testing
We are using composer to install the dependencies: phpunit and Guzzle http client.
So download the latest CodeIgniter 2.x version and create a composer.json file with the following content:
{
"require": {
"guzzlehttp/guzzle": "^6.1",
"phpunit/phpunit": "*",
"phpunit/php-invoker": "*",
"phpunit/dbunit": "*"
}
}
and then install the dependencies using the below command:
$ composer install
Then we create our test file inside application/tests/ folder called PostsTest.php
All the dependencies are included by the autoload file.
require('../../vendor/autoload.php');
Before doing each test case, we setup the Guzzle Http client and set the base uri of the API request as below inside setUp() function which is called before each test function call.
protected function setUp()
{
$this->client = new GuzzleHttp\Client([
'base_uri' => 'http://localhost/'
]);
}
One function is to test get post API request, so we are making a get request to url http://localhost/posts/index/1 to get the first post and are expecting a json content and the json content should have some fields and should have an id value of 1.
public function testGet_ValidInput_PostObject()
{
$response = $this->client->get('posts/index/1');
$this->assertEquals(200, $response->getStatusCode());
$data = json_decode($response->getBody(), true);
$this->assertArrayHasKey('id', $data);
$this->assertArrayHasKey('title', $data);
$this->assertArrayHasKey('content', $data);
$this->assertArrayHasKey('author_id', $data);
$this->assertArrayHasKey('emails_sent', $data);
$this->assertArrayHasKey('created_at', $data);
$this->assertArrayHasKey('updated_at', $data);
$this->assertEquals(1, $data['id']);
}
So we are using assertArrayHasKey() function to check if a particular field is present in the data set and assertEquals() to check for value.
Another function is to test POST request to create a new blog post.
public function testPost_NewBlog_Post()
{
$response = $this->client->post('posts/index', [
'form_params' => [
'title' => 'My Random Post',
'content' => 'Content',
'author_id' => 1
]
]);
$this->assertEquals(200, $response->getStatusCode());
$data = json_decode($response->getBody(), true);
$this->assertGreaterThanOrEqual(1, $data['id']);
}
In the above function we are creating a post request to the url http://localhost/posts/index with post parameters and are then expecting a 200 status code output and a json content with a field "id" which should have an integer value greater than or equal to 1.
Now that we are done with the tests, we can run them from the project root directory using below command:
$ ./vendor/bin/phpunit application/tests/
Basically phpunit and Guzzle Http client help us in making requests and verify responses thus enabling us to test APIs.
Ref: https://ole.michelsen.dk/blog/testing-your-api-with-phpunit.html
Excerpt: "Remember it's just as important to test failing/edge cases as testing when things go well. Also you should run these tests against an isolated testing environment if they modify your data."
1. Unit tested at model level to check the logic is working fine
2. Tested at API call level to ascertain whether all the apis as expected are working and are returning data as expected.
Today, we will be learning how to test APIs in CodeIgniter 2.x version using phpunit and Guzzle Http client.
Basically Guzzle Http client is a client used to make http client requests.
Ref: https://github.com/guzzle/guzzle
"Guzzle is a PHP HTTP client that makes it easy to send HTTP requests and trivial to integrate with web services."
We will basically be creating an API for a blog so as to get blog posts and add blog post. When testing APIs, we are basically testing the output format, expected fields in the output and their data type and value if needed.
Sample code can be found at git repository here: https://github.com/satejkumar/CodeIgniter_API_Testing
We are using composer to install the dependencies: phpunit and Guzzle http client.
So download the latest CodeIgniter 2.x version and create a composer.json file with the following content:
{
"require": {
"guzzlehttp/guzzle": "^6.1",
"phpunit/phpunit": "*",
"phpunit/php-invoker": "*",
"phpunit/dbunit": "*"
}
}
and then install the dependencies using the below command:
$ composer install
Then we create our test file inside application/tests/ folder called PostsTest.php
All the dependencies are included by the autoload file.
require('../../vendor/autoload.php');
Before doing each test case, we setup the Guzzle Http client and set the base uri of the API request as below inside setUp() function which is called before each test function call.
protected function setUp()
{
$this->client = new GuzzleHttp\Client([
'base_uri' => 'http://localhost/'
]);
}
One function is to test get post API request, so we are making a get request to url http://localhost/posts/index/1 to get the first post and are expecting a json content and the json content should have some fields and should have an id value of 1.
public function testGet_ValidInput_PostObject()
{
$response = $this->client->get('posts/index/1');
$this->assertEquals(200, $response->getStatusCode());
$data = json_decode($response->getBody(), true);
$this->assertArrayHasKey('id', $data);
$this->assertArrayHasKey('title', $data);
$this->assertArrayHasKey('content', $data);
$this->assertArrayHasKey('author_id', $data);
$this->assertArrayHasKey('emails_sent', $data);
$this->assertArrayHasKey('created_at', $data);
$this->assertArrayHasKey('updated_at', $data);
$this->assertEquals(1, $data['id']);
}
So we are using assertArrayHasKey() function to check if a particular field is present in the data set and assertEquals() to check for value.
Another function is to test POST request to create a new blog post.
public function testPost_NewBlog_Post()
{
$response = $this->client->post('posts/index', [
'form_params' => [
'title' => 'My Random Post',
'content' => 'Content',
'author_id' => 1
]
]);
$this->assertEquals(200, $response->getStatusCode());
$data = json_decode($response->getBody(), true);
$this->assertGreaterThanOrEqual(1, $data['id']);
}
In the above function we are creating a post request to the url http://localhost/posts/index with post parameters and are then expecting a 200 status code output and a json content with a field "id" which should have an integer value greater than or equal to 1.
Now that we are done with the tests, we can run them from the project root directory using below command:
$ ./vendor/bin/phpunit application/tests/
Basically phpunit and Guzzle Http client help us in making requests and verify responses thus enabling us to test APIs.
Ref: https://ole.michelsen.dk/blog/testing-your-api-with-phpunit.html
Excerpt: "Remember it's just as important to test failing/edge cases as testing when things go well. Also you should run these tests against an isolated testing environment if they modify your data."
Sunday, 14 February 2016
A link I found highlighting principles that guide us in development for an ethical web
I found this very simple yet very clear list of principles that can be kept in mind while developing for the web.
https://ethicalweb.org/
Excerpt from above link:
"As web developers, we are responsible for shaping the experiences of user's online lives. By making choices that are ethical and user-centered, we create a better web for everyone."
Hope it helps and guides us in creating a better web for everyone :)
https://ethicalweb.org/
Excerpt from above link:
"As web developers, we are responsible for shaping the experiences of user's online lives. By making choices that are ethical and user-centered, we create a better web for everyone."
Hope it helps and guides us in creating a better web for everyone :)
Subscribe to:
Posts (Atom)

