You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When I run the test under certain conditions, it crashes on EnvironmentInjection in ViewInspector.
I can't identify the conditions that cause the crash because I just changed some code that I don't think is the cause of the crash and I can see the result of whether it crashes or not.
Also, the result does not change with each execution, but always crashes under certain conditions.
Environment
XCode: 15.4
ViewInspector: 0.10.0
Run Destination: Simulator iPhone 15 (17.5)
Crash Details
EXC_BAD_ACCESS is occurring at line 47 of EnvironmentInjection.
import XCTest
import ViewInspector
@testable import ViewInspectorSample
finalclassViewInspectorSampleTests:XCTestCase{overridefunc setUpWithError()throws{
// Put setup code here. This method is called before the invocation of each test method in the class.
}overridefunc tearDownWithError()throws{
// Put teardown code here. This method is called after the invocation of each test method in the class.
}@MainActorfunc testCounter()throws{varsut=ContentView()letexp= sut.on(\.didAppear){ view inletcountText=try view.vStack().text(0).string()XCTAssertEqual(countText,"Count: 0")try view.find(button:"increment").tap()letupdatedText=try view.find(ViewType.Text.self).string()XCTAssertEqual(updatedText,"Count: 1")}ViewHosting.host(view: sut.environmentObject(ViewModel()))wait(for:[exp], timeout: 0.1)}}
If I set Run Destination to Simulator iPhone 14 (16.0), the crash does not occur.
No Crash Code
Fixed the value type ModelA defined in @State.
Just commented out one property.
The value defined in @State is not used anywhere in the View.
With this code, the test succeeds without crashing.
No change in test code.
import SwiftUI
@MainActorclassViewModel:ObservableObject{@Publishedvarcount:Int=0}structContentView:View{@Statevarmodel:ModelA?@EnvironmentObjectvarviewModel:ViewModel#if DEBUGinternalvardidAppear:((Self)->Void)?#endifvarbody:someView{VStack{Text("Count: \(viewModel.count)")Button{
viewModel.count +=1} label:{Text("increment")}Button{
viewModel.count -=1} label:{Text("decrement")}}.padding().onAppear{#if DEBUGself.didAppear?(self)#endif}}}structModelA:Codable{letid:Stringvarproperty1:Stringletproperty2:Stringvarproperty3:Stringletproperty4:Stringletproperty5:Stringletproperty6:Stringvarproperty7:[String]
// let property8: Date <--------------- comment out
letproperty9:Date?varproperty10:Double?varproperty11:ModelB?varproperty12:StatusstructModelB:Codable,Hashable{letid:Stringvarproperty1:[String]}enumStatus:String,Codable{case ready ="READY"case running ="RUNNING"}}
Not only property8, but removing other properties from ModelA or changing the type definition will no longer cause crashes.
We are strongly considering adopting ViewInspector for our project.
I wish you the best of luck in resolving this issue. Best regards.
The text was updated successfully, but these errors were encountered:
When I run the test under certain conditions, it crashes on EnvironmentInjection in ViewInspector.
I can't identify the conditions that cause the crash because I just changed some code that I don't think is the cause of the crash and I can see the result of whether it crashes or not.
Also, the result does not change with each execution, but always crashes under certain conditions.
Environment
Crash Details
EXC_BAD_ACCESS is occurring at line 47 of EnvironmentInjection.
Crashing Code
View under test↓
Test code↓
If I set Run Destination to Simulator iPhone 14 (16.0), the crash does not occur.
No Crash Code
Fixed the value type ModelA defined in
@State
.Just commented out one property.
The value defined in
@State
is not used anywhere in the View.With this code, the test succeeds without crashing.
No change in test code.
Not only property8, but removing other properties from ModelA or changing the type definition will no longer cause crashes.
We are strongly considering adopting ViewInspector for our project.
I wish you the best of luck in resolving this issue. Best regards.
The text was updated successfully, but these errors were encountered: