-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f53ef60
commit ab152b2
Showing
13 changed files
with
3,916 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
distributionBase=GRADLE_USER_HOME | ||
distributionPath=wrapper/dists | ||
distributionUrl=https\://services.gradle.org/distributions/gradle-7.4.2-all.zip | ||
distributionUrl=https\://services.gradle.org/distributions/gradle-7.5-rc-2-all.zip | ||
zipStoreBase=GRADLE_USER_HOME | ||
zipStorePath=wrapper/dists |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package pl.mareklangiewicz.uspek.sample.compose | ||
|
||
@RunWith(USpekJUnit4Runner::class) | ||
class SomeComposeUSpek { | ||
init { | ||
uspekLog = { | ||
if (it.failed) Log.e("uspek", it.status) | ||
else Log.w("uspek", it.status) | ||
} | ||
} | ||
|
||
@get:Rule | ||
val rule = createComposeRule() | ||
|
||
@Test | ||
fun simpleTest() = assertEquals(2, 2) | ||
@Test | ||
fun simpleFailingTest() = assertEquals(3, 4) | ||
|
||
@USpekTestTree(6) | ||
fun layoutUSpek() = with(rule) { | ||
"On simple box content" o { | ||
setContent { | ||
Box { | ||
Text("First simple box") | ||
} | ||
} | ||
} | ||
"On second nothing test" o { | ||
setContent { | ||
Box(Modifier.background(Color.Blue)) { | ||
Text("Second simple box") | ||
} | ||
} | ||
sleep(1800) | ||
assertEquals(4, 4) | ||
} | ||
"On third nothing test" o { | ||
assertEquals(5, 5) | ||
"On inner UI test" o { | ||
setContent { | ||
Box(Modifier.background(Color.Cyan)) { | ||
Text("Third inner box") | ||
} | ||
} | ||
"wait a bit with content and fail" o { | ||
sleep(1000) | ||
fail() | ||
} | ||
"wait a bit again with content and finish" o { | ||
sleep(1000) | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
/build | ||
/out | ||
/.idea | ||
/.gradle | ||
/local.properties |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
import org.jetbrains.kotlin.gradle.plugin.* | ||
import pl.mareklangiewicz.defaults.* | ||
import pl.mareklangiewicz.deps.* | ||
import pl.mareklangiewicz.utils.* | ||
|
||
plugins { | ||
kotlin("jvm") | ||
application | ||
} | ||
|
||
defaultBuildTemplateForJvmApp( | ||
appMainPackage = "pl.mareklangiewicz.ktjunit4sample", | ||
withTestJUnit4 = true, | ||
withTestJUnit5 = false, | ||
) { | ||
implementation(project(":uspekx-junit4")) | ||
} | ||
|
||
// region [Kotlin Module Build Template] | ||
|
||
fun TaskCollection<Task>.defaultKotlinCompileOptions( | ||
jvmTargetVer: String = vers.defaultJvm, | ||
requiresOptIn: Boolean = true | ||
) = withType<org.jetbrains.kotlin.gradle.tasks.KotlinCompile>().configureEach { | ||
kotlinOptions { | ||
jvmTarget = jvmTargetVer | ||
if (requiresOptIn) freeCompilerArgs = freeCompilerArgs + "-Xopt-in=kotlin.RequiresOptIn" | ||
} | ||
} | ||
|
||
// endregion [Kotlin Module Build Template] | ||
|
||
// region [Jvm App Build Template] | ||
|
||
@Suppress("UNUSED_VARIABLE") | ||
fun Project.defaultBuildTemplateForJvmApp( | ||
appMainPackage: String, | ||
appMainClass: String = "MainKt", | ||
details: LibDetails = libs.Unknown, | ||
withTestJUnit4: Boolean = false, | ||
withTestJUnit5: Boolean = true, | ||
withTestUSpekX: Boolean = true, | ||
addMainDependencies: KotlinDependencyHandler.() -> Unit = {} | ||
) { | ||
repositories { defaultRepos() } | ||
defaultGroupAndVerAndDescription(details) | ||
|
||
kotlin { | ||
sourceSets { | ||
val main by getting { | ||
dependencies { | ||
addMainDependencies() | ||
} | ||
} | ||
val test by getting { | ||
dependencies { | ||
if (withTestJUnit4) implementation(deps.junit4) | ||
if (withTestJUnit5) implementation(deps.junit5engine) | ||
if (withTestUSpekX) implementation(deps.uspekx) | ||
} | ||
} | ||
} | ||
} | ||
|
||
application { mainClass put "$appMainPackage.$appMainClass" } | ||
|
||
tasks.defaultKotlinCompileOptions() | ||
tasks.defaultTestsOptions(onJvmUseJUnitPlatform = withTestJUnit5) | ||
} | ||
|
||
// endregion [Jvm App Build Template] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package pl.mareklangiewicz.ktjvmsample | ||
|
||
fun main(args: Array<String>) { | ||
val calc = MicroCalc(0) | ||
println(calc.result) | ||
calc.add(10) | ||
println(calc.result) | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package pl.mareklangiewicz.ktjvmsample | ||
|
||
|
||
class MicroCalc(var result: Int) { | ||
fun add(x: Int) { result += x } | ||
fun multiplyBy(x: Int) { result *= x } | ||
fun ensureResultIs(expectedResult: Int) = | ||
check(result == expectedResult) { "result is not: $expectedResult; it is actually: $result" } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
package pl.mareklangiewicz.ktjvmsample | ||
|
||
import org.junit.runner.* | ||
import pl.mareklangiewicz.uspek.* | ||
|
||
@RunWith(USpekJUnit4Runner::class) | ||
class JUnit4MicroCalcTest { | ||
|
||
@USpekTestTree(18) | ||
fun microCalcTest() { | ||
|
||
"create SUT" o { | ||
|
||
val sut = MicroCalc(10) | ||
|
||
"check add" o { | ||
sut.add(5) | ||
sut.result eq 15 | ||
sut.add(100) | ||
sut.result eq 115 | ||
} | ||
|
||
"mutate SUT" o { | ||
sut.add(1) | ||
|
||
@Suppress("Deprecation") | ||
"incorrectly check add - this should fail" ox { | ||
sut.add(5) | ||
sut.result eq 15 | ||
} | ||
} | ||
|
||
"check add again" o { | ||
sut.add(5) | ||
sut.result eq 15 | ||
sut.add(100) | ||
sut.result eq 115 | ||
} | ||
|
||
testSomeAdding(sut) | ||
|
||
"mutate SUT and check multiplyBy" o { | ||
sut.result = 3 | ||
|
||
sut.multiplyBy(3) | ||
sut.result eq 9 | ||
sut.multiplyBy(4) | ||
sut.result eq 36 | ||
|
||
testSomeAdding(sut) | ||
} | ||
|
||
"assure that SUT is intact by any of sub tests above" o { | ||
sut.result eq 10 | ||
} | ||
} | ||
} | ||
|
||
@USpekTestTree(2) | ||
fun loggingTest() { | ||
val sut = MicroCalc(10) | ||
"blaaaaa" o { | ||
sut.result eq 10 | ||
"blee" o { | ||
sut.result eq 10 | ||
} | ||
} | ||
} | ||
|
||
|
||
private fun testSomeAdding(calc: MicroCalc) { | ||
val start = calc.result | ||
"add 5 to $start" o { | ||
calc.add(5) | ||
val afterAdd5 = start + 5 | ||
"result should be $afterAdd5" o { calc.result eq afterAdd5 } | ||
|
||
"add 7 more" o { | ||
calc.add(7) | ||
val afterAdd5Add7 = afterAdd5 + 7 | ||
"result should be $afterAdd5Add7" o { calc.result eq afterAdd5Add7 } | ||
} | ||
} | ||
|
||
"subtract 3" o { | ||
calc.add(-3) | ||
val afterSub3 = start - 3 | ||
"result should be $afterSub3" o { calc.result eq afterSub3 } | ||
} | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
*.iml | ||
.gradle | ||
/local.properties | ||
.idea | ||
/build | ||
/out |
Oops, something went wrong.