나는 그것을 수행하는 방법에 대한 문서를 찾지 못했지만 알아낼 수있는 충분한 정보가 ScalaDocs에있었습니다. 이런 일을하고 싶어하는 사람들을 위해 여기에 당신이 알아야 할 것이 있습니다 :
먼저,이 추가 동작을 얻기 위해 혼합 할 수있는 자신의 특성을 정의하고 싶을 것입니다. 그것은과 같이) 태그 (의 정의를 무시합니다 : 구현은 super.tags
를 호출 한 다음 그것을 반환하기 전에 결과 데이터 구조에 추가 될 필요가 어떤 추가해야합니다
trait _____ extends SuiteMixin with Informing { this: Suite with Informing =>
// with Informing, etc. is so that you can call info()
// to add comments to tests - not strictly needed for this
abstract override def tags : Map[String, Set[String]] = {
// implementation
}
}
. 결과의 키는 테스트 이름이 될 것이고, 값은 태그 문자열의 집합이 될 것입니다. 참고 : 태그가없는 테스트는 표시되지 않으므로 해당 객체를 반복 실행하여 작업 할 테스트를 찾을 수 없습니다. 결국 this.testNames
에 전화를 걸고 그걸 반복해야합니다.
다음은 내가 작성한 코드의 예입니다.이 코드는이 문제를 해결하는 방법을 보여줍니다.
abstract override def tags : Map[String, Set[String]] = {
val original = super.tags
val matching = <list of what to automatically add tags to>
if (matching.isEmpty) original
else {
val tests = this.testNames.toList
def extend(result: Map[String, Set[String]], test_list: List[String]) : Map[String, Set[String]] =
if (test_list.isEmpty) result
else {
val matches = (for (p <- matching if (<applicable>)) yield true) contains true
if (! matches) extend(result, test_list.tail)
else extend(
result.updated(
test_list.head,
result.getOrElse(test_list.head, Set[String]())
+ "<tag-to-be-added>"),
test.tail
)
}
extend(original, tests)
}
}
희망은 나와 다른 사람에게 도움이되기를 바랍니다.
더 우아한 방법이나 scala-esque 방식에 대한 의견을 환영하며 높이 평가합니다.