且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Xcode UI测试-使用存储的凭据登录/注销

更新时间:2023-12-04 18:11:40

我遇到了相同类型的问题.经过一番抨击之后,我***的方法是尝试使事情变得更简单.在泪流满面的时候,我总是放松"我可能做过的任何事情.有时它是过大的,但仍然是很好的做法.如果进行某种硬重置,在发现可能会忽略它们的地方时,我发现了许多错误. IE:我将导航回到主页(我的起点),如果我已经登录,那么我只是退出即可.作为记录,在应用程序侧,当用户注销时,其凭据将被剥夺.

I've ran into the same types of issues. After a bunch of bashing around my best approach was to try and keep things a little more simple. In my tear downs I always "unwind" anything that I might have done. Some times it's overkill but it's still good practice. I've found many bugs while unwinding where I might have overlooked them if I did some sort of hard reset. IE: I'll navigate back to the home page (my starting point) and if I've signed in then I'll simply just sign out. For the record, on the app side when a users signs out, their credentials are stripped.

例如,在我的SignInTests.swift类上,我将所有方法放在同一个类文件中的扩展名中.这样,我可以简单地调用SignInTests().signIn()或SignInTests().signOut(),这样我就可以从任何其他可能要调用signOut()的测试类中访问它们.

So for example, on my SignInTests.swift classes I put all my methods in an extension in the same class file. That way I can simply call SignInTests().signIn() or SignInTests().signOut() so that I can access them from whatever other test class I might to called signOut() from.

这是我的理想选择.可能不是您的***选择,但我希望它为您指明了正确的方向.

This is my scenario that works perfectly for me. May not be the best option for you but I hope it points you in the right direction.