मैं कोटलिन में एक स्पेक टेस्ट लिखना चाहता हूं। परीक्षण को src/test/resources
फ़ोल्डर से एक HTML फ़ाइल पढ़नी चाहिए। यह कैसे करना है?कोटलिन में संसाधनों से टेक्स्ट फ़ाइल कैसे पढ़ा जाए?
class MySpec : Spek({
describe("blah blah") {
given("blah blah") {
var fileContent : String = ""
beforeEachTest {
// How to read the file file.html in src/test/resources/html
fileContent = ...
}
it("should blah blah") {
...
}
}
}
})
मुझे इस काम नहीं किया के लिए, मैं इस 'को बदलना पड़ा: : class.java.classLoader.getResource ("/ html/file.html")। readText() ' – pk1914
मेरे लिए ये दोनों विकल्प एंड्रॉइड ऐप में काम करते हैं (उनमें से एक में अतिरिक्त'/'देखें, डब्ल्यू जिसे दूसरे में हटा दिया जाना है): 'this :: class.java.getResource ("/html/file.html ")। readText()' और 'this :: class.java.classLoader.getResource (" html/file.html ")। readText()' – Franco