This article is part of a series on Testing with Codeception in general and How we start our Automation Testing with Codeception in PHP in particular:
- Part 1: What is Codeception?
- Part 2: How to install Codeception?
- Part 3: Get started with Codeception?
Here we’re discussing Codeception, what is Codeception and why we use Codeception in testing. Before Codeception we have to know about what is Testing, it means to validate or verify any software or technology.
We use Codeception framework for testing in any application now Codeception is testing framework for PHP in which we write Acceptance, Functional and Unit Test scenarios.
Acceptance Testing means testing done on the client side, it is also called User Acceptance Testing which means to verify any product on the client side.
Functional Testing means testing done to check the functionality of system whether our applications are working fine or not.
Unit Testing means unit part of components of the application is going to be tested. Now Welcome to the world of Codeception, It allows writing Unit, Functional, Integration, and Acceptance tests in a single, coherent style.
All Codeception tests are written in a descriptive manner. Just by looking at the test body, you can clearly understand what is being tested and how it is performed. Likewise, we have many frameworks in testing but in Codeception we associated with BDD (Behavior Driven Development) framework and TDD (Test driven development) now to understand Codeception we have to go through above two development framework.
The Main advantage of Codeception is we do not have to work for only one type of testing, we have all Three! and later or sooner we will need all Three. That’s why Codeception consists “Suites” means collection. A “Unit suite” for all Unit tests, a “Functional suite” for all Functional tests, and an “Acceptance suite” for all Acceptance tests.
Here We use Codeception testing to test Create Ticket Panel in UVdesk.
Now we are using two type of framework in Codeception, that is BDD means “Behavior Driven Development” and TDD means “Test Driven development”, TDD focuses on how something will work, BDD focuses on why we build it at all.
what is BDD and why BDD?
BDD is normally for a nontechnical user, who is not able to understand any codes or framework like, we write scenarios in simple language below is the example for testing the Create Ticket request in UVdesk.
BDD test scenarios Represent Like:
I am user. I am on page Creative uvdesk.com. I click on CONTACT US. Then Create ticket Request page appear. I fill field "Username" "davert". I fillfield "Username" "davert". I fillfield "Subject" "qwerty". I fillfield "email id" "email@example.com. I fillfield "Type" "name of issue". I fillfield "Message" " message" I click "Create Ticket". I see Message "Ticket generate Successfully."
so basically our purpose is to write scenarios which are easily understood by the Non-technical person in BDD framework.
As in above module, we know about BDD framework but one most important name associated with BDD that is ‘Behat‘. Behat is a tool that makes BDD possible and Behat is test framework for behavior driven development and Behat is written in PHP programming framework in a simple way, we can say Behat is used to make communication easy between clients and developers and many other during software development process. Behat scenarios are a series of Given, When and Then like an example is given below.
Behat is a tool that makes BDD possible and Behat is test framework for behavior driven development and Behat is written in PHP programming framework in a simple way, we can say Behat is used to make communication easy between clients and developers and many other during software development process. Behat scenarios are a series of Given, When and Then like an example is given below.
As a customer, I have some query regarding any product. I want to create a ticket in UVdesk panel regarding my product.
scenarios are described as:
Given the product name regarding which I have to generate a query. Valid product details like product name and product description. When I go to creative uvdesk.com. Then I click on CONTACT US button and we can see Create Ticket Request form. I fill my all correct detail and then I create my ticket in UVdesk.
These are the scenario of How Behat will work and it Represent BDD framework, so non-technical people easily understand the scenarios.
Now we will talk about TDD, TDD makes you think about the required behavior and hence the term ‘Behavior’ is more useful than the term ‘Test’. BDD is Behavior Driven Development which focuses on behavior and not tests. So here we discuss codes which are used to run our scenarios in TDD framework. A significant advantage of TDD is, it enables you to take small steps when writing software.
TDD is neither about “Testing” nor about “Design”.
TDD does not mean “write some of the tests, then build a system that passes the tests.
TDD does not mean “do lots of Testing”.
Before we perform TDD test, we have to know about basic guidelines.
I click() method is used to click a link and buttons. I amOnUrl() method is used to justify on which link or URL You using. I fillfield() method is used to fill the forms. I getCurrentUrl() is used to get the current page url. I selectoption() is used to select option. I chekoption() is used to select the check box.
These are the basic terms that we have to know before we start using TDD framework in testing.
Below are the examples for testing the Create Ticket in UVdesk in TDD manner, in which we test how a user can create a ticket in UVdesk.
$I->wantTo('log in as regular user'); $this->loginAsRegularUser($I); $I->amOnUrl('https://creative.uvdesk.com'); $I->click('Contact Us'); $I->see('Create Ticket Request'); $I->fillfield('name','shivani'); $I->fillfield('from','firstname.lastname@example.org'); $I->selectoption('type','221'); $I->fillfield('subject','Ticket11'); $I->fillfield('customFields','11'); $I->filfield('customFields', '25'); $I->checkoption('#forcheck262'); $I->checkOption('#forcheck1263'); $I->seeCheckboxIsChecked('input[id=forcheck1263]'); $I->see('Success ! Ticket has been created successfully.');