Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
S
skiko
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
liuqiang
skiko
Commits
093421cf
Commit
093421cf
authored
Jan 15, 2021
by
Igor Demin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Screenshot based testing
parent
620547af
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
113 additions
and
14 deletions
+113
-14
test.run.xml
.run/test.run.xml
+25
-0
build.gradle
samples/SkijaInjectSample/build.gradle
+11
-0
AppTest.kt
...InjectSample/src/test/kotlin/SkijaInjectSample/AppTest.kt
+0
-14
Images.kt
...njectSample/src/test/kotlin/org/jetbrains/skiko/Images.kt
+18
-0
ScreenshotTestRule.kt
...src/test/kotlin/org/jetbrains/skiko/ScreenshotTestRule.kt
+59
-0
No files found.
.run/test.run.xml
0 → 100644
View file @
093421cf
<component
name=
"ProjectRunConfigurationManager"
>
<configuration
default=
"false"
name=
"test"
type=
"GradleRunConfiguration"
factoryName=
"Gradle"
>
<ExternalSystemSettings>
<option
name=
"executionName"
/>
<option
name=
"externalProjectPath"
value=
"$PROJECT_DIR$/samples/SkijaInjectSample"
/>
<option
name=
"externalSystemIdString"
value=
"GRADLE"
/>
<option
name=
"scriptParameters"
value=
""
/>
<option
name=
"taskDescriptions"
>
<list
/>
</option>
<option
name=
"taskNames"
>
<list>
<option
value=
"test"
/>
</list>
</option>
<option
name=
"vmOptions"
value=
""
/>
</ExternalSystemSettings>
<ExternalSystemDebugServerProcess>
true
</ExternalSystemDebugServerProcess>
<ExternalSystemReattachDebugProcess>
true
</ExternalSystemReattachDebugProcess>
<DebugAllEnabled>
false
</DebugAllEnabled>
<method
v=
"2"
>
<option
name=
"Gradle.BeforeRunTask"
enabled=
"false"
tasks=
"publishToMavenLocal"
externalProjectPath=
"$PROJECT_DIR$/skiko"
vmOptions=
""
scriptParameters=
""
/>
</method>
</configuration>
</component>
\ No newline at end of file
samples/SkijaInjectSample/build.gradle
View file @
093421cf
...
@@ -56,4 +56,15 @@ application {
...
@@ -56,4 +56,15 @@ application {
run
{
run
{
systemProperty
(
"skiko.fps.enabled"
,
"true"
)
systemProperty
(
"skiko.fps.enabled"
,
"true"
)
}
test
{
systemProperty
(
"skiko.test.screenshots.dir"
,
new
File
(
project
.
projectDir
,
"src/test/screenshots"
).
absolutePath
)
// Tests should be determined, so disable scaling.
// On MacOs we need the actual scale, otherwise we will have aliased screenshots because of scaling.
if
(
System
.
getProperty
(
"os.name"
)
!=
"Mac OS X"
)
{
systemProperty
(
"sun.java2d.dpiaware"
,
"false"
)
systemProperty
(
"sun.java2d.uiScale"
,
"1"
)
}
}
}
\ No newline at end of file
samples/SkijaInjectSample/src/test/kotlin/SkijaInjectSample/AppTest.kt
deleted
100644 → 0
View file @
620547af
/*
* This Kotlin source file was generated by the Gradle 'init' task.
*/
package
SkijaInjectSample
import
kotlin.test.Test
import
kotlin.test.assertNotNull
class
AppTest
{
// @Test fun testAppHasAGreeting() {
// val classUnderTest = App()
// assertNotNull(classUnderTest.greeting, "app should have a greeting")
// }
}
samples/SkijaInjectSample/src/test/kotlin/org/jetbrains/skiko/Images.kt
0 → 100644
View file @
093421cf
package
org.jetbrains.skiko
import
java.awt.image.BufferedImage
fun
isContentSame
(
img1
:
BufferedImage
,
img2
:
BufferedImage
):
Boolean
{
if
(
img1
.
width
==
img2
.
width
&&
img1
.
height
==
img2
.
height
)
{
for
(
x
in
0
until
img1
.
width
)
{
for
(
y
in
0
until
img1
.
height
)
{
if
(
img1
.
getRGB
(
x
,
y
)
!=
img2
.
getRGB
(
x
,
y
))
{
return
false
}
}
}
}
else
{
return
false
}
return
true
}
\ No newline at end of file
samples/SkijaInjectSample/src/test/kotlin/org/jetbrains/skiko/ScreenshotTestRule.kt
0 → 100644
View file @
093421cf
package
org.jetbrains.skiko
import
org.junit.rules.TestRule
import
org.junit.runner.Description
import
org.junit.runners.model.Statement
import
java.awt.Rectangle
import
java.awt.Robot
import
java.io.File
import
javax.imageio.ImageIO
// TODO macOs has wrong colors. Only white, black, red and green are correct
class
ScreenshotTestRule
(
private
val
robot
:
Robot
)
:
TestRule
{
private
lateinit
var
testIdentifier
:
String
private
val
screenshotsDir
=
File
(
System
.
getProperty
(
"skiko.test.screenshots.dir"
)
!!
)
override
fun
apply
(
base
:
Statement
,
description
:
Description
):
Statement
{
return
object
:
Statement
()
{
override
fun
evaluate
()
{
testIdentifier
=
"${description.className}_${description.methodName}"
.
replace
(
"."
,
"_"
)
.
replace
(
","
,
"_"
)
.
replace
(
" "
,
"_"
)
.
replace
(
"("
,
"_"
)
.
replace
(
")"
,
"_"
)
.
replace
(
"__"
,
"_"
)
.
replace
(
"__"
,
"_"
)
.
removePrefix
(
"_"
)
.
removeSuffix
(
"_"
)
base
.
evaluate
()
}
}
}
fun
assert
(
rectangle
:
Rectangle
,
id
:
String
=
""
)
{
val
actual
=
robot
.
createScreenCapture
(
rectangle
)
val
name
=
if
(
id
.
isNotEmpty
())
"${testIdentifier}_$id"
else
testIdentifier
val
actualFile
=
File
(
screenshotsDir
,
"${name}_actual.png"
)
val
expectedFile
=
File
(
screenshotsDir
,
"$name.png"
)
if
(
actualFile
.
exists
())
{
actualFile
.
delete
()
}
if
(
expectedFile
.
exists
())
{
val
expected
=
ImageIO
.
read
(
expectedFile
)
if
(!
isContentSame
(
expected
,
actual
))
{
ImageIO
.
write
(
actual
,
"png"
,
actualFile
)
throw
AssertionError
(
"Image mismatch! Expected image ${expectedFile.absolutePath}, actual: ${actualFile.absolutePath}"
)
}
}
else
{
ImageIO
.
write
(
actual
,
"png"
,
actualFile
)
throw
AssertionError
(
"Missing screenshot image "
+
"${actualFile.absolutePath}. "
+
"Did you mean to check in a new image?"
)
}
}
}
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment