我有UIView
(contentBGView
)代表边框视图。任务是如果url可用于显示边框,如果没有则显示没有边框。
我如何对此代码进行单元测试?
if contentUrlExists {
addSubview(contentBGView)
contentBGView.addSubview(contentTextView)
contentBGView.addSubview(mediaView)
contentBGView.isHidden = false
statesTextView.anchor(locationLabel.bottomAnchor, left: self.leftAnchor, bottom: contentBGView.topAnchor, right: self.rightAnchor, topConstant: 5, leftConstant: 10, bottomConstant: 2, rightConstant: 5, widthConstant: 0, heightConstant: 0)
contentBGView.anchor(statesTextView.bottomAnchor, left: self.leftAnchor, bottom: statisticsSlidingBarCollectionView.topAnchor, right: self.rightAnchor, topConstant: 0, leftConstant: 5, bottomConstant: 10, rightConstant: 5, widthConstant: 0, heightConstant: 0)
mediaView.anchor(contentBGView.topAnchor, left: contentBGView.leftAnchor, bottom: nil, right: contentBGView.rightAnchor, topConstant: 5, leftConstant: 4, bottomConstant: 2, rightConstant: 4, widthConstant: 0, heightConstant: 0)
contentTextView.anchor(mediaView.bottomAnchor, left: contentBGView.leftAnchor, bottom: contentBGView.bottomAnchor, right: contentBGView.rightAnchor, topConstant: 5, leftConstant: 5, bottomConstant: 2, rightConstant: 5, widthConstant: 0, heightConstant: stateConetentTextHeight)
statisticsSlidingBarCollectionView.anchor(contentBGView.bottomAnchor, left: self.leftAnchor, bottom: self.bottomAnchor, right: self.rightAnchor, topConstant: 0, leftConstant: 5, bottomConstant: 0, rightConstant: 5, widthConstant: 0, heightConstant: 45)
}else{
addSubview(mediaView)
contentBGView.isHidden = true
statesTextView.anchor(locationLabel.bottomAnchor, left: self.leftAnchor, bottom: mediaView.topAnchor, right: self.rightAnchor, topConstant: 5, leftConstant: 10, bottomConstant: 2, rightConstant: 5, widthConstant: 0, heightConstant: 0)
mediaView.anchor(statesTextView.bottomAnchor, left: self.leftAnchor, bottom: statisticsSlidingBarCollectionView.topAnchor, right: self.rightAnchor, topConstant: 0, leftConstant: 0, bottomConstant: 2, rightConstant: 0, widthConstant: 0, heightConstant: 160)
statisticsSlidingBarCollectionView.anchor(mediaView.bottomAnchor, left: self.leftAnchor, bottom: self.bottomAnchor, right: self.rightAnchor, topConstant: 0, leftConstant: 5, bottomConstant: 0, rightConstant: 5, widthConstant: 0, heightConstant: 45)
}
根据内容网址正确显示边框的单元测试 谢谢
答案 0 :(得分:1)
这取决于您要测试它的部分和程度。如果您的UI测试可以看到contentBGView
,那么您只需测试它是否为isHidden
。如果您想更具体,可以将各个子视图与预期值进行比较,但在我看来,没有必要在该级别进行测试。