如何使用 Behat 在 Laravel 5 中测试注册表?如何写一个功能?
How to test registration form in Laravel 5 with Behat ? How to write a feature?
我必须使用 Behat测试我的 Larravel 应用程序 ,并且
我写了 Laravel 应用程序满足:
A user opens the web application in his/her browser
The user enters his/her name and email into the registration form
The user clicks the 'Register' button below the form
The application registers the user (name/email) in the database
The application redirects the user to a page that contains a “Thank
you” message.***
我必须写 Behat 功能,但我不知道从哪里开始?我读过 BDD 但仍然感到困惑。
还应该包含单元测试 用于非 UTF-8 等基本内容
输入、空表单和非字符串输入。
是这样的吗?
Feature: Registation form
In order to test register on this site
As a visitor
I need to fill in the necessary info
Scenario:
Given I am on the homepage
When I fill in "username" with "Chrismo"
And I fill in "email" with "chris@chrismo.com"
Then I should see "THank you"
您需要将所有功能文件写入 features
文件夹。
例如,如果你想为 functional
测试编写一个功能,你可以创建一个名为 welcome.feature
的文件并将其放在 features/functional
文件夹中。
对于单元测试,Behat 本身没有断言。所以,您可能想要使用 PHPUnit 的断言。由于 PHPUnit 与新的 Laravel 应用程序捆绑在一起,它已经可用,访问断言所需要做的就是在 Behat 的 FeatureContext class 中导入 class,如下所示:
use PHPUnit_Framework_Assert as PHPUnit;
然后您将可以访问断言并编写测试。
编辑:这是您可以遵循的详细教程:https://blog.vinelab.net/building-reliable-apis-using-bdd-behant-laravel-5-949156a37e66#.yv89tcqkw
我已阅读有关测试级别的信息:验收、功能、集成和单元。
我不确定前两个之间有什么区别。告诉我如果我错了但是在上面的例子中
接受度将创建这样的功能:
Feature: Registation form
In order to test register on this site
As a visitor
I need to fill in the necessary info
Scenario:
Given I am on the homepage
When I fill in "name" with "Chrismo"
And I fill in "email" with "chris@chrismo.com"
And I press "Register"
Then I should see "THank you".
在功能上,必须做什么?也许 "somehow" 检查用户是否保存在用户 table(数据库)中?
我必须使用 Behat测试我的 Larravel 应用程序 ,并且 我写了 Laravel 应用程序满足:
A user opens the web application in his/her browser
The user enters his/her name and email into the registration form
The user clicks the 'Register' button below the form
The application registers the user (name/email) in the database
The application redirects the user to a page that contains a “Thank you” message.***
我必须写 Behat 功能,但我不知道从哪里开始?我读过 BDD 但仍然感到困惑。
还应该包含单元测试 用于非 UTF-8 等基本内容 输入、空表单和非字符串输入。
是这样的吗?
Feature: Registation form
In order to test register on this site
As a visitor
I need to fill in the necessary info
Scenario:
Given I am on the homepage
When I fill in "username" with "Chrismo"
And I fill in "email" with "chris@chrismo.com"
Then I should see "THank you"
您需要将所有功能文件写入 features
文件夹。
例如,如果你想为 functional
测试编写一个功能,你可以创建一个名为 welcome.feature
的文件并将其放在 features/functional
文件夹中。
对于单元测试,Behat 本身没有断言。所以,您可能想要使用 PHPUnit 的断言。由于 PHPUnit 与新的 Laravel 应用程序捆绑在一起,它已经可用,访问断言所需要做的就是在 Behat 的 FeatureContext class 中导入 class,如下所示:
use PHPUnit_Framework_Assert as PHPUnit;
然后您将可以访问断言并编写测试。
编辑:这是您可以遵循的详细教程:https://blog.vinelab.net/building-reliable-apis-using-bdd-behant-laravel-5-949156a37e66#.yv89tcqkw
我已阅读有关测试级别的信息:验收、功能、集成和单元。 我不确定前两个之间有什么区别。告诉我如果我错了但是在上面的例子中
接受度将创建这样的功能:
Feature: Registation form
In order to test register on this site
As a visitor
I need to fill in the necessary info
Scenario:
Given I am on the homepage
When I fill in "name" with "Chrismo"
And I fill in "email" with "chris@chrismo.com"
And I press "Register"
Then I should see "THank you".
在功能上,必须做什么?也许 "somehow" 检查用户是否保存在用户 table(数据库)中?