在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称(OpenSource Name):GAumala/KotlinSnapshot开源软件地址(OpenSource Url):https://github.com/GAumala/KotlinSnapshot开源编程语言(OpenSource Language):Java 93.8%开源软件介绍(OpenSource Introduction):KotlinSnapshotSnapshot testing in Kotlin. The implementation of the diff algorithm used is taken from diff-match-patch. InstallDownload with gradle from JitPack. First add the JitPack repository to your root allprojects {
repositories {
...
maven { url 'https://jitpack.io' }
}
} Then on your module's dependencies {
testImplementation 'com.github.GAumala:KotlinSnapshot:0.1'
}
UsageCreate an instance of class NetworkTest {
private val camera = Camera()
private val networkClient = MyNetworkClient()
@Test
fun shouldFetchDataFromNetwork() {
val myData = networkClient.fetchData()
camera.matchWithSnapshot("should fetch data from network", myData)
} After you run the test for the first time, a new snapshot will be written in the $ cat __snapshot__/should\ fetch\ data\ from\ network.snap
{"name":"gabriel","id":5} On subsequent runs, the value will be compared with the snapshot stored in the filesystem if the are not equal, your test will fail. To see the detailed error you may need to run your tests with You can also specify the path relative to the project's root where you want the snapshot dir to be placed using val camera = Camera(relativePath = "src/test/kotlin/com/my/package") Updating SnapshotsIn order to update and purge snapshots from the command line, you should add a new system property called "updateSnapshots" to your test {
// update snapshots via command line
systemProperty "updateSnapshots", System.getProperty("u")
} On android projects you might need to do this instead: testOptions {
unitTests.all {
// update snapshots via command line
systemProperty "updateSnapshots", System.getProperty("u")
}
} Then, when you want to update the snapshot for a specific test: ./gradlew test -Du=1 --info --tests *MyTest.someTestINeedToUpdate Please note that in this example I used "u" but, it can be any flag, depending on how you configure your gradle file. On android projects the Purging SnapshotsAs you rename snapshots, old unused snapshots may remain in your project. You can delete all existing snapshots and rebuild the ones that are actually used using the "purgeSnapshots" system property. The setup is identical to the one used for updating snapshots. test {
// purge snapshots via command line
systemProperty "purgeSnapshots", System.getProperty("p")
} Again android projects may need to handle this differently: testOptions {
unitTests.all {
// update snapshots via command line
systemProperty "purgeSnapshots", System.getProperty("p")
}
} Then, when you want to delete the snapshots: ./gradlew test -Dp=1 --info |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论