unit-testing - 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')
解决方案
推荐阅读
- python - Python - 如何从数据列表中为每个月创建一个新的数据框
- javascript - 如何停止播放声音,或者如何让它播放一次?
- post - TypeError:预检响应不成功
- python - 需要帮助解决 Pandas 中的排序错误
- maven - 在带有 Maven 的 IntelliJ 中找不到依赖项 'org.jetbrains.kotlin:kotlin-maven-noarg:1.4.31'
- c++ - 如何实现 constexpr N-way set_union(去重合并)
- sql-server - 在 SQL 的存储过程中使用递归?
- function - 我如何把它变成一个函数?
- python - 维度超出范围(预计在 [-4, 3] 范围内,但得到 64)
- visual-studio-code - 在 VSCode 中,为什么 Prettier 会格式化我的代码,然后将其突出显示为错误?