-
Notifications
You must be signed in to change notification settings - Fork 32
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
Showing
11 changed files
with
135 additions
and
127 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
2 changes: 1 addition & 1 deletion
2
app/src/androidTest/kotlin/net/pot8os/kotlintestsample/InstrumentedCalculatorTest.kt
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,20 +1,20 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" | ||
package="net.pot8os.kotlintestsample"> | ||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"> | ||
|
||
<application | ||
android:allowBackup="true" | ||
android:icon="@mipmap/ic_launcher" | ||
android:label="@string/app_name" | ||
android:supportsRtl="true" | ||
android:theme="@style/Theme.MyApp"> | ||
<activity android:name="net.pot8os.kotlintestsample.MainActivity"> | ||
<intent-filter> | ||
<action android:name="android.intent.action.MAIN" /> | ||
|
||
<category android:name="android.intent.category.LAUNCHER" /> | ||
</intent-filter> | ||
</activity> | ||
</application> | ||
<application | ||
android:allowBackup="true" | ||
android:icon="@mipmap/ic_launcher" | ||
android:label="@string/app_name" | ||
android:supportsRtl="true" | ||
android:theme="@style/Theme.MyApp"> | ||
<activity | ||
android:name="net.pot8os.kotlintestsample.MainActivity" | ||
android:exported="true"> | ||
<intent-filter> | ||
<action android:name="android.intent.action.MAIN" /> | ||
<category android:name="android.intent.category.LAUNCHER" /> | ||
</intent-filter> | ||
</activity> | ||
</application> | ||
|
||
</manifest> |
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,75 @@ | ||
package net.pot8os.kotlintestsample | ||
|
||
import androidx.fragment.app.testing.launchFragmentInContainer | ||
import androidx.test.espresso.Espresso.onView | ||
import androidx.test.espresso.action.ViewActions.click | ||
import androidx.test.espresso.assertion.ViewAssertions.matches | ||
import androidx.test.espresso.matcher.ViewMatchers.withId | ||
import androidx.test.espresso.matcher.ViewMatchers.withText | ||
import org.junit.Before | ||
import org.junit.Test | ||
import java.text.DecimalFormat | ||
|
||
/** | ||
* @author So Nakamura, 2020-Feb-15 | ||
*/ | ||
abstract class CalculatorSpec { | ||
|
||
@Before | ||
fun setup() { | ||
launchFragmentInContainer<CalculatorFragment>(themeResId = R.style.Theme_MyApp) | ||
} | ||
|
||
@Test | ||
fun testSum() { | ||
onView(withId(R.id.button_1)).perform(click()) | ||
onView(withId(R.id.button_2)).perform(click()) | ||
onView(withId(R.id.button_3)).perform(click()) | ||
onView(withId(R.id.button_sum)).perform(click()) | ||
onView(withId(R.id.button_3)).perform(click()) | ||
onView(withId(R.id.button_2)).perform(click()) | ||
onView(withId(R.id.button_1)).perform(click()) | ||
onView(withId(R.id.button_calc)).perform(click()) | ||
onView(withId(R.id.field)).check(matches(withText("${123 + 321}"))) | ||
} | ||
|
||
@Test | ||
fun testSub() { | ||
onView(withId(R.id.button_9)).perform(click()) | ||
onView(withId(R.id.button_9)).perform(click()) | ||
onView(withId(R.id.button_9)).perform(click()) | ||
onView(withId(R.id.button_sub)).perform(click()) | ||
onView(withId(R.id.button_3)).perform(click()) | ||
onView(withId(R.id.button_3)).perform(click()) | ||
onView(withId(R.id.button_3)).perform(click()) | ||
onView(withId(R.id.button_calc)).perform(click()) | ||
onView(withId(R.id.field)).check(matches(withText("${999 - 333}"))) | ||
} | ||
|
||
@Test | ||
fun testMul() { | ||
onView(withId(R.id.button_1)).perform(click()) | ||
onView(withId(R.id.button_0)).perform(click()) | ||
onView(withId(R.id.button_0)).perform(click()) | ||
onView(withId(R.id.button_mul)).perform(click()) | ||
onView(withId(R.id.button_2)).perform(click()) | ||
onView(withId(R.id.button_0)).perform(click()) | ||
onView(withId(R.id.button_0)).perform(click()) | ||
onView(withId(R.id.button_calc)).perform(click()) | ||
val formatter = DecimalFormat("#,###") | ||
onView(withId(R.id.field)).check(matches(withText(formatter.format(100 * 200)))) | ||
} | ||
|
||
@Test | ||
fun testDiv() { | ||
onView(withId(R.id.button_3)).perform(click()) | ||
onView(withId(R.id.button_3)).perform(click()) | ||
onView(withId(R.id.button_3)).perform(click()) | ||
onView(withId(R.id.button_div)).perform(click()) | ||
onView(withId(R.id.button_1)).perform(click()) | ||
onView(withId(R.id.button_0)).perform(click()) | ||
onView(withId(R.id.button_0)).perform(click()) | ||
onView(withId(R.id.button_calc)).perform(click()) | ||
onView(withId(R.id.field)).check(matches(withText("${333 / 100.0}"))) | ||
} | ||
} |
77 changes: 0 additions & 77 deletions
77
app/src/testShared/kotlin/net.pot8s.kotlintestsample/CalculatorSpec.kt
This file was deleted.
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
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,38 +1,40 @@ | ||
import org.gradle.kotlin.dsl.DependencyHandlerScope | ||
|
||
fun DependencyHandlerScope.kotlin() { | ||
implementation("org.jetbrains.kotlin:kotlin-stdlib:1.3.72") | ||
implementation("org.jetbrains.kotlin:kotlin-stdlib:1.9.22") | ||
} | ||
|
||
fun DependencyHandlerScope.fragment() { | ||
val version = "1.2.5" | ||
val version = "1.6.2" | ||
implementation("androidx.fragment:fragment-ktx:$version") | ||
debugImplementation("androidx.fragment:fragment-testing:$version") | ||
androidTestImplementation("androidx.fragment:fragment-testing:1.6.0") | ||
} | ||
|
||
fun DependencyHandlerScope.compat() { | ||
implementation("androidx.appcompat:appcompat:1.1.0") | ||
implementation("androidx.appcompat:appcompat:1.6.1") | ||
} | ||
|
||
fun DependencyHandlerScope.layout() { | ||
implementation("androidx.constraintlayout:constraintlayout:1.1.3") | ||
implementation("com.google.android.material:material:1.1.0") | ||
implementation("androidx.constraintlayout:constraintlayout:2.1.4") | ||
implementation("com.google.android.material:material:1.11.0") | ||
} | ||
|
||
fun DependencyHandlerScope.viewmodel() { | ||
implementation("androidx.lifecycle:lifecycle-viewmodel-ktx:2.2.0") | ||
implementation("androidx.lifecycle:lifecycle-viewmodel-ktx:2.7.0") | ||
} | ||
|
||
fun DependencyHandlerScope.test() { | ||
// These dependencies are consumed in both unit tests and instrumented tests. | ||
debugImplementation("androidx.test.espresso:espresso-core:3.2.0") | ||
debugImplementation("androidx.test:runner:1.2.0") | ||
debugImplementation("androidx.test:rules:1.2.0") | ||
debugImplementation("androidx.test.ext:junit-ktx:1.1.1") | ||
debugImplementation("androidx.test.espresso:espresso-core:3.5.1") | ||
debugImplementation("androidx.test:runner:1.5.2") | ||
debugImplementation("androidx.test:rules:1.5.0") | ||
debugImplementation("androidx.test.ext:junit-ktx:1.1.5") | ||
// Regarding robolectric, only test target is sufficient. | ||
testImplementation("org.robolectric:robolectric:4.3.1") | ||
testImplementation("org.robolectric:robolectric:4.11.1") | ||
} | ||
|
||
private const val implementation = "implementation" | ||
private const val debugImplementation = "debugImplementation" | ||
private const val testImplementation = "testImplementation" | ||
private const val androidTestImplementation = "androidTestImplementation" |
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