SpekJava 測試規(guī)范框架
Spek 是 JetBrains 開發(fā)的 JVM 的一個規(guī)范框架,通過優(yōu)雅的 DSL 來清晰描述你的代碼規(guī)范,主要用于 Kotlin 語言的測試。
一般的測試代碼:
@Test
public void testCalculateTaxRate() {
TaxRateCalculator calculator = new TaxRateCalculator();
Int value = calculator.calculateRate(200, 10);
assertEquals(300,value);
}
使用 Spek 的測試代碼:
class TaxCalculatorSpecs: Spek() {{
given("Tax rate calculator with default locale settings") {
val taxRateCalculator = TaxRateCalculator()
on("calculating the rate for an income of 200 and an average change of 10 per semester") {
val value = taxRateCalculator.calculateRate(200, 10)
it("should result in a value of 300") {
assertEquals(300, value)
}
}
}
}}評論
圖片
表情
