How to test 2 methods with common logic?
问题 Let's say that I have 2 public methods: func didSelect(data: Data) { // do something self.view.showText(textForData(data)) } func didDismiss(data: Data) { if data.isSomething { self.view.showText(textForData(data)) } ... } private func textForData(data: Data): String { var text: String if data.distance == nil { text = "..." } else if data.distance < 1000 { text = "\(data.distance) m" } else { text = "\(data.distance / 1000) km" } return text } Both of them depend on the formatting logic of