kandi background
Explore Kits

testing-samples | samples demonstrating different frameworks | Unit Testing library

 by   android Java Version: Current License: Apache-2.0

 by   android Java Version: Current License: Apache-2.0

Download this library from

kandi X-RAY | testing-samples Summary

testing-samples is a Java library typically used in Testing, Unit Testing, Selenium applications. testing-samples has no bugs, it has no vulnerabilities, it has a Permissive License and it has medium support. However testing-samples build file is not available. You can download it from GitHub.
A collection of samples demonstrating different frameworks and techniques for automated testing
Support
Support
Quality
Quality
Security
Security
License
License
Reuse
Reuse

kandi-support Support

  • testing-samples has a medium active ecosystem.
  • It has 8470 star(s) with 3461 fork(s). There are 483 watchers for this library.
  • It had no major release in the last 12 months.
  • There are 79 open issues and 115 have been closed. On average issues are closed in 79 days. There are 31 open pull requests and 0 closed requests.
  • It has a neutral sentiment in the developer community.
  • The latest version of testing-samples is current.
testing-samples Support
Best in #Unit Testing
Average in #Unit Testing
testing-samples Support
Best in #Unit Testing
Average in #Unit Testing

quality kandi Quality

  • testing-samples has 0 bugs and 0 code smells.
testing-samples Quality
Best in #Unit Testing
Average in #Unit Testing
testing-samples Quality
Best in #Unit Testing
Average in #Unit Testing

securitySecurity

  • testing-samples has no vulnerabilities reported, and its dependent libraries have no vulnerabilities reported.
  • testing-samples code analysis shows 0 unresolved vulnerabilities.
  • There are 0 security hotspots that need review.
testing-samples Security
Best in #Unit Testing
Average in #Unit Testing
testing-samples Security
Best in #Unit Testing
Average in #Unit Testing

license License

  • testing-samples is licensed under the Apache-2.0 License. This license is Permissive.
  • Permissive licenses have the least restrictions, and you can use them in most projects.
testing-samples License
Best in #Unit Testing
Average in #Unit Testing
testing-samples License
Best in #Unit Testing
Average in #Unit Testing

buildReuse

  • testing-samples releases are not available. You will need to build from source code and install.
  • testing-samples has no build file. You will be need to create the build yourself to build the component from source.
  • Installation instructions are not available. Examples and code snippets are available.
  • It has 5825 lines of code, 291 functions and 279 files.
  • It has low code complexity. Code complexity directly impacts maintainability of the code.
testing-samples Reuse
Best in #Unit Testing
Average in #Unit Testing
testing-samples Reuse
Best in #Unit Testing
Average in #Unit Testing
Top functions reviewed by kandi - BETA

Coming Soon for all Libraries!

Currently covering the most popular Java, JavaScript and Python libraries. See a SAMPLE HERE.
kandi's functional review helps you automatically verify the functionalities of the libraries and avoid rework.

testing-samples Key Features

A collection of samples demonstrating different frameworks and techniques for automated testing

default

copy iconCopydownload iconDownload
- Android SDK v28
- Android Build Tools v28.03

Getting Started
---------------

These samples use the Gradle build system. To build a project, enter the project directory and use the `./gradlew assemble` command or use "Import Project" in Android Studio.

- Use `./gradlew connectedAndroidTest` to run the tests on a connected emulator or device.
- Use `./gradlew test` to run the unit test on your local host.

There is a top-level `build.gradle` file if you want to build and test all samples from the root directory. This is mostly helpful to build on a CI (Continuous Integration) server.

AndroidX Test Library
---------------
Many of these samples use the AndroidX Test Library. Visit the [Testing site on developer.android.com](https://developer.android.com/training/testing) for more information.

Experimental Bazel Support
--------------------------

[![Build status](https://badge.buildkite.com/18dda320b265e9a8f20cb6141b1e80ca58fb62bdb443e527be.svg)](https://buildkite.com/bazel/android-testing)

Some of these samples can be tested with [Bazel](https://bazel.build) on Linux. These samples contain a `BUILD.bazel` file, which is similar to a `build.gradle` file. The external dependencies are defined in the top level `WORKSPACE` file.

This is __experimental__ feature. To run the tests, please install the latest version of Bazel (0.12.0 or later) by following the [instructions on the Bazel website](https://docs.bazel.build/versions/master/install-ubuntu.html).

### Bazel commands

```
# Clone the repository if you haven't.
$ git clone https://github.com/google/android-testing
$ cd android-testing

# Edit the path to your local SDK at the top of the WORKSPACE file
$ $EDITOR WORKSPACE

# Test everything in a headless mode (no graphical display)
$ bazel test //... --config=headless

# Test a single test, e.g. ui/espresso/BasicSample/BUILD.bazel
$ bazel test //ui/uiautomator/BasicSample:BasicSampleInstrumentationTest_21_x86 --config=headless

# Query for all android_instrumentation_test targets
$ bazel query 'kind(android_instrumentation_test, //...)'
//ui/uiautomator/BasicSample:BasicSampleInstrumentationTest_23_x86
//ui/uiautomator/BasicSample:BasicSampleInstrumentationTest_22_x86
//ui/uiautomator/BasicSample:BasicSampleInstrumentationTest_21_x86
//ui/uiautomator/BasicSample:BasicSampleInstrumentationTest_19_x86
//ui/espresso/RecyclerViewSample:RecyclerViewSampleInstrumentationTest_23_x86
//ui/espresso/RecyclerViewSample:RecyclerViewSampleInstrumentationTest_22_x86
//ui/espresso/RecyclerViewSample:RecyclerViewSampleInstrumentationTest_21_x86
//ui/espresso/RecyclerViewSample:RecyclerViewSampleInstrumentationTest_19_x86
//ui/espresso/MultiWindowSample:MultiWindowSampleInstrumentationTest_23_x86
//ui/espresso/MultiWindowSample:MultiWindowSampleInstrumentationTest_22_x86
...

# Test everything with GUI enabled
$ bazel test //... --config=gui

# Test with a local device or emulator. Ensure that `adb devices` lists the device.
$ bazel test //... --config=local_device

# If multiple devices are connected, add --device_serial_number=$identifier where $identifier is the name of the device in `adb devices`
$ bazel test //... --config=local_device --test_arg=--device_serial_number=$identifier
```

For more information, check out the documentation for [Android Instrumentation Tests in Bazel](https://docs.bazel.build/versions/master/android-instrumentation-test.html). You may also want to check out [Building an Android App with Bazel](https://docs.bazel.build/versions/master/tutorial/android-app.html), and the list of [Android Rules](https://docs.bazel.build/versions/master/be/android.html) in the Bazel Build Encyclopedia.

Known issues:

* Building of APKs is supported on Linux, Mac and Windows, but testing is only supported on Linux.
* `android_instrumentation_test.target_device` attribute still needs to be specified even if `--config=local_device` is used.
* If using a local device or emulator, the APKs are not uninstalled automatically after the test. Use this command to
remove the packages:
    * `adb shell pm list packages com.example.android.testing | cut -d ':' -f 2 | tr -d '\r' | xargs -L1 -t adb uninstall`

Please file Bazel related issues against the [Bazel](https://github.com/bazelbuild/bazel) repository instead of this repository.

Support
-------

- Google+ Community: https://plus.google.com/communities/105153134372062985968
- Stack Overflow: http://stackoverflow.com/questions/tagged/android-testing

If you've found an error in this sample, please file an issue:
https://github.com/googlesamples/android-testing

Patches are encouraged, and may be submitted by forking this project and
submitting a pull request through GitHub. Please see CONTRIBUTING.md for more details.

License
-------

Copyright 2015 The Android Open Source Project, Inc.

Licensed to the Apache Software Foundation (ASF) under one or more contributor
license agreements.  See the NOTICE file distributed with this work for
additional information regarding copyright ownership.  The ASF licenses this
file to you under the Apache License, Version 2.0 (the "License"); you may not
use this file except in compliance with the License.  You may obtain a copy of
the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
License for the specific language governing permissions and limitations under
the License.

Espresso webview test with kotlin

copy iconCopydownload iconDownload
private fun withWebFormIntent(context: Context): Intent {
    return Intent(context, MainActivity::class.java).also {
        val keyUrl2Load = "KEY_URL_TO_LOAD"
        val webFormUrl = "file:///android_asset/web_form.html"
        it.putExtra(keyUrl2Load, webFormUrl)
    }
}

Community Discussions

Trending Discussions on testing-samples
  • Espresso webview test with kotlin
Trending Discussions on testing-samples

QUESTION

Espresso webview test with kotlin

Asked 2021-May-12 at 17:22

I'm trying to port the Espresso sample from Java to Kotlin, I got an error for the WebView version

I'm using the name MainActivity.kt as is, it just simple and works well:

class MainActivity : AppCompatActivity() {
    @VisibleForTesting
    val keyUrl2Load = "KEY_URL_TO_LOAD"

    @VisibleForTesting
    val webFormUrl = "file:///android_asset/web_form.html"

    private var mWebView: WebView? = null

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)

        mWebView = findViewById<View>(R.id.web_view) as WebView
        true.also { mWebView!!.settings.javaScriptEnabled = it }
        urlFromIntent(intent)?.let { mWebView!!.loadUrl(it) }
        mWebView!!.requestFocus()
        mWebView!!.webViewClient = object : WebViewClient() {
            override fun shouldOverrideUrlLoading(view: WebView, url: String): Boolean {
                return false
            }
        }
    }

    private fun urlFromIntent(intent: Intent): String? {
        val url = intent.getStringExtra(keyUrl2Load)
        return if (!TextUtils.isEmpty(url)) url else webFormUrl
    }
}

However, the MainActivityTest.kt looks not that easy to port, as:

package com.example.espressowebview101

import android.content.Intent
import androidx.test.core.app.ActivityScenario
import androidx.test.espresso.web.assertion.WebViewAssertions
import androidx.test.espresso.web.sugar.Web
import androidx.test.espresso.web.webdriver.DriverAtoms
import androidx.test.espresso.web.webdriver.Locator
import androidx.test.ext.junit.rules.activityScenarioRule
import androidx.test.ext.junit.runners.AndroidJUnit4
import org.hamcrest.Matchers
import org.junit.After
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith

//https://github.com/android/testing-samples/tree/main/ui/espresso/WebBasicSample/app/src
@RunWith(AndroidJUnit4::class)
class MainActivityTest {
    private val MACCHIATO = "Macchiato"
    private val DOPPIO = "Doppio"
    lateinit var scenario: ActivityScenario<MainActivity>


    @get:Rule
    var mActivityRule = activityScenarioRule<MainActivity>()

    @After
    fun enableJS() {
        Web.onWebView().forceJavascriptEnabled()
    }

    @Test
    fun typeTextInInput_clickButton_SubmitsForm() {
        val intent = withWebFormIntent()
        scenario = ActivityScenario.launch(intent)

        // Selects the WebView in your layout. If you have multiple WebViews you can also use a
        // matcher to select a given WebView, onWebView(withId(R.id.web_view)).
        Web.onWebView() // Find the input element by ID
            .withElement(DriverAtoms.findElement(Locator.ID, "text_input")) // Clear previous input
            .perform(DriverAtoms.clearElement()) // Enter text into the input element
            .perform(DriverAtoms.webKeys(MACCHIATO)) // Find the submit button
            .withElement(
                DriverAtoms.findElement(
                    Locator.ID,
                    "submitBtn"
                )
            ) // Simulate a click via javascript
            .perform(DriverAtoms.webClick()) // Find the response element by ID
            .withElement(
                DriverAtoms.findElement(
                    Locator.ID,
                    "response"
                )
            ) // Verify that the response page contains the entered text
            .check(
                WebViewAssertions.webMatches(
                    DriverAtoms.getText(),
                    Matchers.containsString(MACCHIATO)
                )
            )
    }

    private fun withWebFormIntent(): Intent {
        return Intent().also {
            val keyUrl2Load = "KEY_URL_TO_LOAD"
            val webFormUrl = "file:///android_asset/web_form.html"
            it.putExtra(keyUrl2Load, webFormUrl)
        }
    }
}

And I got error as:

Connected to process 8963 on device 'google-pixel_3_xl-8AJY0LJFQ'.

java.lang.RuntimeException: Unable to resolve activity for: Intent { (has extras) }
    at androidx.test.core.app.InstrumentationActivityInvoker.startActivity(InstrumentationActivityInvoker.java:387)
    at androidx.test.core.app.InstrumentationActivityInvoker.startActivity(InstrumentationActivityInvoker.java:416)
    at androidx.test.core.app.ActivityScenario.launchInternal(ActivityScenario.java:265)
    at androidx.test.core.app.ActivityScenario.launch(ActivityScenario.java:226)
    at com.example.espressowebview101.MainActivityTest.typeTextInInput_clickButton_SubmitsForm(MainActivityTest.kt:36)
    at java.lang.reflect.Method.invoke(Native Method)
    at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
    at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
    at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
    at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
    at androidx.test.internal.runner.junit4.statement.RunAfters.evaluate(RunAfters.java:61)
    at org.junit.rules.ExternalResource$1.evaluate(ExternalResource.java:48)
    at org.junit.rules.RunRules.evaluate(RunRules.java:20)
    at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
    at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
    at androidx.test.ext.junit.runners.AndroidJUnit4.run(AndroidJUnit4.java:154)
    at org.junit.runners.Suite.runChild(Suite.java:128)
    at org.junit.runners.Suite.runChild(Suite.java:27)
    at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
    at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
    at org.junit.runner.JUnitCore.run(JUnitCore.java:115)
    at androidx.test.internal.runner.TestExecutor.execute(TestExecutor.java:56)
    at androidx.test.runner.AndroidJUnitRunner.onStart(AndroidJUnitRunner.java:395)
    at android.app.Instrumentation$InstrumentationThread.run(Instrumentation.java:2205)

ANSWER

Answered 2021-May-12 at 17:22

You are trying to launch an Intent which is not related to MainActivity whatsoever. It doesn't know that it should launch this activity.

Your withWebFormIntent should return an Intent that tells it to launch MainActivity.

E.g.

private fun withWebFormIntent(context: Context): Intent {
    return Intent(context, MainActivity::class.java).also {
        val keyUrl2Load = "KEY_URL_TO_LOAD"
        val webFormUrl = "file:///android_asset/web_form.html"
        it.putExtra(keyUrl2Load, webFormUrl)
    }
}

See this for more documentation on how to construct an intent for an activity.

Source https://stackoverflow.com/questions/67504879

Community Discussions, Code Snippets contain sources that include Stack Exchange Network

Vulnerabilities

No vulnerabilities reported

Install testing-samples

You can download it from GitHub.
You can use testing-samples like any standard Java library. Please include the the jar files in your classpath. You can also use any IDE and you can run and debug the testing-samples component as you would do with any other Java program. Best practice is to use a build tool that supports dependency management such as Maven or Gradle. For Maven installation, please refer maven.apache.org. For Gradle installation, please refer gradle.org .

Support

For any new features, suggestions and bugs create an issue on GitHub. If you have any questions check and ask questions on community page Stack Overflow .

DOWNLOAD this Library from

Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from
over 430 million Knowledge Items
Find more libraries
Reuse Solution Kits and Libraries Curated by Popular Use Cases

Save this library and start creating your kit

Explore Related Topics

Share this Page

share link
Reuse Pre-built Kits with testing-samples
Consider Popular Unit Testing Libraries
Compare Unit Testing Libraries with Highest Support
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from
over 430 million Knowledge Items
Find more libraries
Reuse Solution Kits and Libraries Curated by Popular Use Cases

Save this library and start creating your kit

  • © 2022 Open Weaver Inc.