首页 > 解决方案 > Phpunit 在一起运行所有测试时显示随机测试用例中的错误

问题描述

我在 PHPUnit 上为网站的浏览器测试制作了许多测试用例,当我单独运行它们时,所有这些测试都通过了,但是当我尝试将它们作为一组或使用php artisan dusk命令运行时,其中一些测试失败了。真正的问题是,每当我一起运行它们时,每次都会在不同的测试用例中出现错误。 我在互联网上搜索并找到了RefreshDatabase命令DatabaseTransaction,但我不能使用它们,因为它不是一个合适的解决方案,我的同事也不允许。请让我知道我缺少什么或者我应该添加什么以顺利运行所有测试。PSI 希望将它们一起运行以在服务器上自动部署(测试然后部署更改)

下面是一个示例测试,可以清楚地理解该问题:

<?php

namespace Tests\Browser;

use Tests\DuskTestCase;
use Laravel\Dusk\Browser;

use Illuminate\Foundation\Testing\DatabaseMigrations;

class AddUsrSegmentTest extends DuskTestCase
{
     

    /**
     * create a user segment
     *
     * @return void
     * @group other
     */
    public function testExample()
    {
        $this->browse(function (Browser $browser) {
              $browser->loginAs(\App\Model\User::find(4567))
              ->visit('/home')
           
              ->clickLink('Create From Scratch')

              ->assertPathis('/bot/dashboard')
                //first create a user datastore
                   ->visit('/bot/datastore')
              ->assertSee('Create a Global/User Datastore')
              ->visit('/bot/datastore/create')
              ->assertSee('Custom Values')
              ->click('#showCustomInput')
              ->type('key','colorsss')    
              //->type('.bootstrap-tagsinput > input:nth-child(1)','apple')
              //->keys('.bootstrap-tagsinput > input:nth-child(1)','mango', ['{enter}'])
              ->keys('.bootstrap-tagsinput > input:nth-child(1)','green', ['{enter}'],'mustard',['{enter}'],'blue',['{enter}'],'red',['{enter}'])


              

              ->click('.slider')

              ->assertSee('Add Datastore')
              ->click('button.btn:nth-child(1)')// add datastore button
              ->visit('/bot/datastore')
              ->assertSeeIn('#zero-config','colorsss')
                

标签: unit-testingautomated-testsphpunit

解决方案


推荐阅读