I need to have a registered user for each of my unit tests, which forces me to make an asynchronous call (login) in my SetUp test.
I canβt find a way to make this work, I either get null pointer exceptions or invalid signatures for installation.
public async void SetUp() {}
This makes my test fail with my objects, probably because I have not logged in.
public async Task SetUp() {}
Makes all my tests ignored because the installation has an invalid signature.
And I would not want to copy my X strings in each test, since they are all the same and ... what the setup is for.
What am I missing? it looks like a trivial problem.
That's what I have now, for the sake of showing something
CreateTicketViewModel _viewModel; [SetUp()] public async void SetUp() //I have tried using Task instead of void { IUserService userService = Dependency.Instance.Resolve<IUserService>(); await userService.LoginAsync(this.UserName, this.Password); _viewModel = Dependency.Instance.Resolve<CreateTicketViewModel>(); } [TearDown()] public void TearDown() { _viewModel = null; // I have tried removing this } [Test()] public void Initialization() { // If I put what in SetUp here and add "async" before void, // it works just fine Assert.IsNotNull(_viewModel); Assert.IsNotNull(_viewModel.Ticket); }
source share