我是新手 C# 和 .NET,并且在编写测试时使用 规范流,我得到了错误 系统NullReferenceException:对象引用未设置为对象的实例
显然,当我试图访问;回答&引用;在其他测试方法中,对象是 无效的,但我不知道为什么。
我在这里搜索,我发现的问题(这一个和这一个)并不能解决我的问题。文章源自玩技e族-https://www.playezu.com/190375.html
我的step文件:文章源自玩技e族-https://www.playezu.com/190375.html
[Binding]
public sealed class UsersSteps
{
private Http回答Message 回答 { get; set; } = 无效的!;
private static readonly HttpClient Client = new HttpClient();
[Given(@"I access the users route (.*)")]
public async void GivenIAccessTheUsersRoute(string baseUrl)
{
var url = new Uri(baseUrl);
回答 = await Client.GetAsync(url);
Console.WriteLine(">> Here it works: " + 回答.StatusCode);
}
[Then(@"I should have only 1 registered user")]
public void ThenIShouldHaveOnlyOneRegisteredUsers()
{
Console.WriteLine(">> Does not work here: " + 回答.StatusCode);
}
[StepDefinition(@"should be admin")]
public void AndShouldBeAdmin()
{
Console.WriteLine(">> Does not work here: " + 回答.StatusCode);
}
[StepDefinition(@"your name should be Fulano da Silva")]
public void AndYourNameShouldBeFulanoDaSilva()
{
Console.WriteLine(">> Does not work here: " + 回答.StatusCode);
}
}
我的功能文件:文章源自玩技e族-https://www.playezu.com/190375.html
Scenario: List users
Given I access the users route https://serverest.dev/usuarios
Then I should have only 1 registered users
And should be admin
And your name should be Fulano da Silva
软件测试功能测试工具文章源自玩技e族-https://www.playezu.com/190375.html 文章源自玩技e族-https://www.playezu.com/190375.html
未知地区 1F
关键部分是评论:
确保您的方法签名是 异步任务不 异步void