【问题标题】:Set a variable in Test Class - Laravel 5.5 Unit Test在测试类中设置一个变量 - Laravel 5.5 单元测试
【发布时间】:2018-05-06 08:04:58
【问题描述】:

我在测试类 Laravel 5.5 中初始化了这个变量

public $token;

在 testA() 中我设置了这个变量

$this->token = "xxx";

我需要在 testB() 中获取这个变量的值,但是当我获取时,它返回 null。

我怎样才能得到这个变量的值?

【问题讨论】:

    标签: unit-testing laravel-5 phpunit


    【解决方案1】:

    您不需要类变量。您可以运行 testA 并从那里返回令牌。然后使用@depends-notation 运行 testB 并将 testA 的值作为参数传入。详情请见phpunit documentation

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-08-01
      • 2022-11-20
      • 1970-01-01
      • 1970-01-01
      • 2018-10-27
      • 1970-01-01
      • 2017-07-23
      • 2021-05-12
      相关资源
      最近更新 更多