如何将测试添加到与@fetchrequest一起使用Coredata的SwiftUI视图中?
我正在尝试为SwiftUI视图添加快照测试,该测试正在使用@fetchrequest属性包装器使用核心数据来驱动UI。我想在UI中添加一些逻辑,并想进行一些快照测试以覆盖它。
以下是我要测试的Swiftui视图的片段示例。
struct TeamView: View {
@Environment(\.managedObjectContext) var viewContext
@FetchRequest(sortDescriptors: [SortDescriptor(\.name)])
private var teams: FetchedResults<Team>
var body: some View {
NavigationView {
List {
ForEach(teams, id: \.id) { team in
Text(team.name)
}
}
.navigationTitle(Text(TabItem.team.title))
}
}
}
我如何创建team
对象,然后可以在teamView
中使用以启用测试?
I am trying to add a snapshot test for a SwiftUI view that is using Core Data to drive the UI via the @FetchRequest property wrapper. I would like to add a small bit of logic within the UI and would like to have some snapshot tests to cover it.
Below is a snippet example of the SwiftUI view that I am trying to test.
struct TeamView: View {
@Environment(\.managedObjectContext) var viewContext
@FetchRequest(sortDescriptors: [SortDescriptor(\.name)])
private var teams: FetchedResults<Team>
var body: some View {
NavigationView {
List {
ForEach(teams, id: \.id) { team in
Text(team.name)
}
}
.navigationTitle(Text(TabItem.team.title))
}
}
}
Any ideas how I can create Team
Objects that can then be used within TeamView
to enable testing?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论