请问单元测试的第一个方法设置变量如何作为下一个测试的参数?
我想在方法1中将查询出的第一个油站的id作为后续的变量,但是在后续的测试方法中并没有获取到,请问这样的功能改如何实现?多个测试方法直接是独立运行的吗?
//获取所有的加油站
public function testStationList()
{
$response = $this->post('/car/gas/v1/station_list');
$response->assertStatus(200);
$data = $response->json('data');
//设置油站id
$this->gas_id = (string) $data[0]['gas_id'];
$response->assertJsonStructure([
'status',
'message',
]);
}
public function testDetail()
{
$response = $this->post('/car/gas/v1/apply_invoice', $this->setParam([
'user_id' => $this->user_id,
'gas_id' => $this->gas_id, //这里好像并没有获取到gas_id
]));
$response->assertStatus(200);
$response->assertJsonStructure([
'status',
'message',
]);
@depends