How to read a text file from resources in Kotlin?

后端 未结 10 567
心在旅途
心在旅途 2020-12-08 17:59

I want to write a Spek test in Kotlin. The test should read an HTML file from the src/test/resources folder. How to do it?

class MySpec : Spek({         


        
10条回答
  •  借酒劲吻你
    2020-12-08 18:33

    A slightly different solution:

    class MySpec : Spek({
        describe("blah blah") {
            given("blah blah") {
    
                var fileContent = ""
    
                beforeEachTest {
                    html = this.javaClass.getResource("/html/file.html").readText()
                }
    
                it("should blah blah") {
                    ...
                }
            }
        }
    })
    

提交回复
热议问题