forked from flutter/packages
-
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.
Add Android unit tests to plugin template (#120720)
* Add Java tests * Add Kotlin * Add integration testing * Add cerate tests
- Loading branch information
1 parent
a664f08
commit ef49f56
Showing
7 changed files
with
186 additions
and
24 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
29 changes: 29 additions & 0 deletions
29
...plates/plugin/android-java.tmpl/src/test/java/androidIdentifier/pluginClassTest.java.tmpl
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,29 @@ | ||
package {{androidIdentifier}}; | ||
|
||
import static org.mockito.Mockito.mock; | ||
import static org.mockito.Mockito.verify; | ||
|
||
import io.flutter.plugin.common.MethodCall; | ||
import io.flutter.plugin.common.MethodChannel; | ||
import org.junit.Test; | ||
|
||
/** | ||
* This demonstrates a simple unit test of the Java portion of this plugin's implementation. | ||
* | ||
* Once you have built the plugin's example app, you can run these tests from the command | ||
* line by running `./gradlew testDebugUnitTest` in the `example/android/` directory, or | ||
* you can run them directly from IDEs that support JUnit such as Android Studio. | ||
*/ | ||
|
||
public class {{pluginClass}}Test { | ||
@Test | ||
public void onMethodCall_getPlatformVersion_returnsExpectedValue() { | ||
{{pluginClass}} plugin = new {{pluginClass}}(); | ||
|
||
final MethodCall call = new MethodCall("getPlatformVersion", null); | ||
MethodChannel.Result mockResult = mock(MethodChannel.Result.class); | ||
plugin.onMethodCall(call, mockResult); | ||
|
||
verify(mockResult).success("Android " + android.os.Build.VERSION.RELEASE); | ||
} | ||
} |
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
27 changes: 27 additions & 0 deletions
27
...ates/plugin/android-kotlin.tmpl/src/test/kotlin/androidIdentifier/pluginClassTest.kt.tmpl
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,27 @@ | ||
package {{androidIdentifier}} | ||
|
||
import io.flutter.plugin.common.MethodCall | ||
import io.flutter.plugin.common.MethodChannel | ||
import kotlin.test.Test | ||
import org.mockito.Mockito | ||
|
||
/* | ||
* This demonstrates a simple unit test of the Kotlin portion of this plugin's implementation. | ||
* | ||
* Once you have built the plugin's example app, you can run these tests from the command | ||
* line by running `./gradlew testDebugUnitTest` in the `example/android/` directory, or | ||
* you can run them directly from IDEs that support JUnit such as Android Studio. | ||
*/ | ||
|
||
internal class {{pluginClass}}Test { | ||
@Test | ||
fun onMethodCall_getPlatformVersion_returnsExpectedValue() { | ||
val plugin = {{pluginClass}}() | ||
|
||
val call = MethodCall("getPlatformVersion", null) | ||
val mockResult: MethodChannel.Result = Mockito.mock(MethodChannel.Result::class.java) | ||
plugin.onMethodCall(call, mockResult) | ||
|
||
Mockito.verify(mockResult).success("Android " + android.os.Build.VERSION.RELEASE) | ||
} | ||
} |
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