我一直试图测试事件,我昨天工作了.那是在我开始重构测试代码以防止它过于重复之前.我添加了setUp方法调用以使用ModelFactories生成伪数据.这是在昨天的每个测试案例中完成的,如上所述它正在工作.
我认为这与使用setUp方法有关,但我不知道为什么会这样.首先,我尝试使用setUpBeforeClass()静态方法,因为它只在单元测试运行时运行一次.但是,在第一次调用setUp()之前,实际上并没有设置laravel应用程序......可能的错误可能是什么?这篇文章记录在Laravel中设置PHPUnit测试.
因此,我选择使用setUp方法,只是检查静态属性是否为null,如果它为null则生成数据,如果不是,它就会继续运行.
这是在项目上运行phpunit的输出
? project git:(laravel-5.2-testing) ? phpunit
PHPUnit 5.2.10 by Sebastian Bergmann and contributors.
E 1 / 1 (100%)
Time: 8.94 seconds, Memory: 33.50Mb
There was 1 error:
1) UserEmailNotificationsTest::testNotificationSentOnGroupMediaSaving
Exception: These expected events were not fired: [\App\Events\GroupMediaSaving]
/Users/jcrawford/Dropbox/Work/Viddler/Repositories/l5_media_communities/vendor/laravel/framework/src/Illuminate/Foundation/Testing/Concerns/MocksApplicationServices.php:44
/Users/jcrawford/Dropbox/Work/Viddler/Repositories/l5_media_communities/vendor/laravel/framework/src/Illuminate/Foundation/Testing/TestCase.php:127
FAILURES!
Tests: 1, Assertions: 0, Errors: 1, Skipped: 8.
Run Code Online (Sandbox Code Playgroud)
这是我创建的单元测试文件的代码.
<?php
use Illuminate\Foundation\Testing\WithoutMiddleware;
use Illuminate\Foundation\Testing\DatabaseMigrations;
use Illuminate\Foundation\Testing\DatabaseTransactions;
class UserEmailNotificationsTest extends \TestCase
{
use DatabaseTransactions;
const COMMUNITIES_TO_CREATE = 3;
const USERS_TO_CREATE = 10;
const ADMINS_TO_CREATE = 5; …Run Code Online (Sandbox Code Playgroud) 我有这样写的Behat测试用例:
Feature: Checkout
In order to buy products
As a customer
I need to be able to checkout items in the cart
Background:
Given step 1
And step 2
@Ready
Scenario: Deliver now
When step 3
Then step 4
@NoneReady
Scenario: Deliver later
When step a
Then step b
And step c
@AddressNotCovered
Scenario: Address Not Covered
When step i
Then step ii
Run Code Online (Sandbox Code Playgroud)
如果我在单个标签上运行behat,它就可以正常工作:
$ behat --tags=Ready
Feature: Checkout
In order to buy products
As a customer
I need to …Run Code Online (Sandbox Code Playgroud)