ऐप्लिकेशन की खास सुविधाओं के लिए कार्रवाइयों की जांच लाइब्रेरी

ऐप्लिकेशन की खास सुविधाओं के लिए कार्रवाइयों की जांच लाइब्रेरी (AATL), डेवलपर को इन सुविधाओं का इस्तेमाल करने की अनुमति देती है ऐप्लिकेशन की कार्रवाई के पूरा होने की प्रोसेस की जांच करने के लिए, आम तौर पर, यह काम असल वॉइस क्वेरी या ऐप्लिकेशन की खास सुविधाओं के लिए कार्रवाइयों की जांच करने वाले टूल का इस्तेमाल करके किया जाता है.

लाइब्रेरी से यह पक्का करने में मदद मिलती है कि shortcut.xml का कॉन्फ़िगरेशन सही है और बताए गए Android इंटेंट को शुरू करने की कोशिश सफल रही. ऐप्लिकेशन ऐक्शन टेस्ट लाइब्रेरी, आपके ऐप्लिकेशन की इस क्षमता की जांच करने के लिए एक तरीका उपलब्ध कराती है कि वह Google Assistant के दिए गए इंटेंट और पैरामीटर को पूरा कर सकती है या नहीं. इसके लिए, उन्हें Android डीप लिंक या Android इंटेंट में बदला जाता है. इनका इस्तेमाल, Android गतिविधि को शुरू करने के लिए किया जा सकता है.

परीक्षण, Robolectric यूनिट या इंस्ट्रुमेंटेड टेस्ट के रूप में किया जाता है एक समस्या है. इससे डेवलपर बेहतर तरीके से यह जांच कर पाते हैं कि ऐप्लिकेशन के असल व्यवहार की नकल करके ऐप्लिकेशन को अपडेट किया जा सकता है. बीआईआई की जांच करने के लिए, कस्टम इंटेंट या डीप लिंक फ़ुलफ़िलमेंट, किसी भी इंस्ट्रुमेंटेड टेस्टिंग फ़्रेमवर्क को इस्तेमाल किया गया (यूज़र इंटरफ़ेस (यूआई) Automator, Espresso, JUnit4, Appium, Detox, Calabash).

अगर ऐप्लिकेशन कई भाषाओं में उपलब्ध है, तो डेवलपर यह पुष्टि कर सकते हैं कि ऐप्लिकेशन की काम की क्षमता विभिन्न भाषाओं में सही तरीके से काम कर रही है.

यह कैसे काम करता है

ऐप्लिकेशन के टेस्टिंग एनवायरमेंट में ऐप्लिकेशन की खास सुविधाओं के लिए कार्रवाइयों की टेस्ट लाइब्रेरी को इंटिग्रेट करने के लिए, डेवलपर को यह करना चाहिए app पर नए Robolectric या इंस्ट्रुमेंटेड टेस्ट बनाएं या मौजूदा Robolectric या इंस्ट्रुमेंटेड टेस्ट बनाएं मॉड्यूल का इस्तेमाल करें.

टेस्ट कोड में ये हिस्से शामिल होते हैं:

  • लाइब्रेरी इंस्टेंस की शुरुआत, सामान्य सेटअप तरीके में या टेस्ट केस.
  • हर जांच के लिए, लाइब्रेरी इंस्टेंस के fulfill तरीके को कॉल किया जाता है इससे इंटेंट बनाने वाला नतीजा मिलेगा.
  • इसके बाद, डेवलपर डीप लिंक का दावा करता है या ऐप्लिकेशन के लिए, ग्राहक को आइटम भेजने की प्रोसेस शुरू करता है, और ऐप्लिकेशन की स्थिति पर कस्टम पुष्टि करता है.

Garmin स्मार्टवॉच सेटअप करने से जुड़ी ज़रूरी शर्तें

टेस्ट लाइब्रेरी का इस्तेमाल करने के लिए, ऐप्लिकेशन के लिए कुछ शुरुआती कॉन्फ़िगरेशन उपलब्ध है आपके ऐप्लिकेशन में परीक्षण जोड़ने से पहले आवश्यक है.

कॉन्फ़िगरेशन

ऐप्लिकेशन ऐक्शन टेस्ट लाइब्रेरी का इस्तेमाल करने के लिए, पक्का करें कि आपका ऐप्लिकेशन इस तरह कॉन्फ़िगर किया गया हो:

  • Android Gradle प्लग इन (AGP) इंस्टॉल करें
  • app मॉड्यूल के res/xml फ़ोल्डर में shortcuts.xml फ़ाइल शामिल करें.
  • पक्का करें कि AndroidManifest.xml में <meta-data android:name="android.app.shortcuts" android:resource=”@xml/shortcuts” /> शामिल हो इनमें से कोई एक:
    • <application> टैग
    • लॉन्चर <activity> टैग
  • <capability> एलिमेंट को <shortcuts> एलिमेंट में रखें shortcuts.xml

ऐप्लिकेशन की खास सुविधाओं के लिए कार्रवाइयों की जांच लाइब्रेरी डिपेंडेंसी जोड़ें

  1. इसमें प्रोजेक्ट डेटा स्टोर करने की जगहों की सूची में, Google का डेटा स्टोर करने की जगह जोड़ें settings.gradle:

        allprojects {
            repositories {
                …
                google()
            }
        }
    
  2. ऐप्लिकेशन मॉड्यूल build.gradle फ़ाइल में, AATL डिपेंडेंसी जोड़ें:

        androidTestImplementation 'com.google.assistant.appactions:testing:1.0.0'
    

    पक्का करें कि आपने डाउनलोड की गई लाइब्रेरी के वर्शन नंबर का इस्तेमाल किया हो.

इंटिग्रेशन टेस्ट बनाना

  1. app/src/androidTest में नए टेस्ट बनाएं. Robolectric टेस्ट के लिए, बनाएं app/src/test से कम:

    Kotlin

      
        import android.content.Context
        import android.content.Intent
        import android.widget.TextView
        import androidx.test.core.app.ApplicationProvider
        import androidx.test.core.app.ActivityScenario
        import com.google.assistant.appactions.testing.aatl.AppActionsTestManager
        import com.google.assistant.appactions.testing.aatl.fulfillment.AppActionsFulfillmentIntentResult
        import com.google.assistant.appactions.testing.aatl.fulfillment.AppActionsFulfillmentResult
        import com.google.assistant.appactions.testing.aatl.fulfillment.FulfillmentType
        import com.google.common.collect.ImmutableMap
        import org.junit.Assert.assertEquals
        import org.junit.Before
        import org.junit.runner.RunWith
        import org.junit.Test
        import org.robolectric.RobolectricTestRunner
        …
        @Test
        fun IntentTestExample() {
          val intentParams = mapOf("feature" to "settings")
          val intentName = "actions.intent.OPEN_APP_FEATURE"
          val result = aatl.fulfill(intentName, intentParams)
    
          assertEquals(FulfillmentType.INTENT, result.getFulfillmentType())
    
          val intentResult = result as AppActionsFulfillmentIntentResult
          val intent = intentResult.intent
    
          // Developer can choose to assert different relevant properties of the returned intent, such as the action, activity, package, scheme and so on
          assertEquals("youtube", intent.scheme)
          assertEquals("settings", intent.getStringExtra("featureParam"))
          assertEquals("actions.intent.OPEN_APP_FEATURE", intent.action)
          assertEquals("com.google.android.youtube/.MainActivity",
              intent.component.flattenToShortString())
          assertEquals("com.google.myapp", intent.package)
    
          // Developers can choose to use returned Android Intent to launch and assess the activity. Below are examples for how it will look like for Robolectric and Espresso tests.
          // Please note that the below part is just a possible example of how Android tests are validating Activity functionality correctness for given Android Intent.
    
          // Robolectric example:
          val activity = Robolectric.buildActivity(MainActivity::class.java,
            intentResult.intent).create().resume().get()
    
          val title: TextView = activity.findViewById(R.id.startActivityTitle)
          assertEquals(title?.text?.toString(), "Launching…")
        }
      
    

    Java

      
        import android.content.Context;
        import android.content.Intent;
        import android.widget.TextView;
        import androidx.test.core.app.ApplicationProvider;
        import androidx.test.core.app.ActivityScenario;
        import com.google.assistant.appactions.testing.aatl.AppActionsTestManager;
        import com.google.assistant.appactions.testing.aatl.fulfillment.AppActionsFulfillmentIntentResult;
        import com.google.assistant.appactions.testing.aatl.fulfillment.AppActionsFulfillmentResult;
        import com.google.assistant.appactions.testing.aatl.fulfillment.FulfillmentType;
        import com.google.common.collect.ImmutableMap;
        import org.junit.Assert.assertEquals;
        import org.junit.Before;
        import org.junit.runner.RunWith;
        import org.junit.Test;
        import org.robolectric.RobolectricTestRunner;
        ...
        @Test
          public void IntentTestExample() throws Exception {
            Map<String, String> intentParams = ImmutableMap.of("feature", "settings");
            String intentName = "actions.intent.OPEN_APP_FEATURE";
            AppActionsFulfillmentResult result = aatl.fulfill(intentName, intentParams);
    
            assertEquals(FulfillmentType.INTENT, result.getFulfillmentType());
    
            AppActionsFulfillmentIntentResult intentResult = (AppActionsFulfillmentIntentResult) result;
    
            Intent intent = intentResult.getIntent();
    
            // Developer can choose to assert different relevant properties of the returned intent, such as the action, activity, package, or scheme
            assertEquals("settings", intent.getStringExtra("featureParam"));
            assertEquals("actions.intent.OPEN_APP_FEATURE", intent.getAction());
            assertEquals("com.google.android.youtube/.MainActivity", intent.getComponent().flattenToShortString());
            assertEquals("com.google.myapp", intent.getPackage());
    
            // Developers can choose to use returned Android Intent to launch and assess the   activity. Below are examples for how it will look like for Robolectric and  Espresso tests.
            // Please note that the below part is just a possible example of how Android tests are validating Activity functionality correctness for given Android Intent.
    
            // Robolectric example:
            MainActivity activity = Robolectric.buildActivity(MainActivity.class,intentResult.intent).create().resume().get();
    
            TextView title: TextView = activity.findViewById(R.id.startActivityTitle)
            assertEquals(title?.getText()?.toString(), "Launching…")
          }
      
    

    अगर आप Espresso का इस्तेमाल कर रहे हैं, तो आपको ऐक्टिविटी लॉन्च करने का तरीका बदलना होगा AATL के नतीजों के आधार पर. यहां Espresso का एक उदाहरण दिया गया है. इसमें, ActivityScenario तरीका:

    Kotlin

        
        ActivityScenario.launch<MainActivity>(intentResult.intent);
        Espresso.onView(ViewMatchers.withId(R.id.startActivityTitle))
          .check(ViewAssertions.matches(ViewMatchers.withText("Launching…")))
        
    

    Java

        
          ActivityScenario.launch<MainActivity>(intentResult.intent);
          Espresso.onView(ViewMatchers.withId(R.id.startActivityTitle))
            .check(ViewAssertions.matches(ViewMatchers.withText("Launching…")))
        
    
  2. पैरामीटर मैपिंग में मौजूद नाम और मुख्य प्रॉपर्टी, पैरामीटर दिए गए हैं. उदाहरण के लिए, exercisePlan.forExercise.name GET_EXERCISE_PLAN में पैरामीटर के लिए दस्तावेज़.

  3. Android Context पैरामीटर के साथ एपीआई इंस्टेंस इंस्टैंशिएट करें (इससे हासिल किया गया ApplicationProvider या InstrumentationRegistry):

    • सिंगल मॉड्यूल ऐप्लिकेशन आर्किटेक्चर:

    Kotlin

        
          private lateinit var aatl: AppActionsTestManager
          @Before
          fun init() {
            val appContext = ApplicationProvider.getApplicationContext()
            aatl = AppActionsTestManager(appContext)
          }
        
      

    Java

        
          private AppActionsTestManager aatl;
    
          @Before
          public void init() {
            Context appContext = ApplicationProvider.getApplicationContext();
            aatl = new AppActionsTestManager(appContext);
          }
        
      
    • मल्टी-मॉड्यूल ऐप्लिकेशन का आर्किटेक्चर:

    Kotlin

        
          private lateinit var aatl: AppActionsTestManager
    
          @Before
          fun init() {
            val appContext = ApplicationProvider.getApplicationContext()
            val lookupPackages = listOf("com.myapp.mainapp", "com.myapp.resources")
            aatl = AppActionsTestManager(appContext, lookupPackages)
          }
        
      

    Java

        
          private AppActionsTestManager aatl;
    
          @Before
          public void init() throws Exception {
    
            Context appContext = ApplicationProvider.getApplicationContext();
            List<String> lookupPackages = Arrays.asList("com.myapp.mainapp","com.myapp.resources");
            aatl = new AppActionsTestManager(appContext, Optional.of(lookupPackages));
          }
        
      
  4. एपीआई का fulfill तरीका इस्तेमाल करें और AppActionsFulfillmentResult ऑब्जेक्ट.

दावे करना

ऐप्लिकेशन की खास सुविधाओं के लिए कार्रवाइयों की जांच लाइब्रेरी पर दावा करने का सुझाव, यहां दिया गया तरीका है:

  1. AppActionsFulfillmentResult के फ़ुलफ़िलमेंट टाइप का दावा करें. इसे FulfillmentType.INTENT या FulfillmentType.UNFULFILLED होना चाहिए यह जांच करने के लिए कि ऐप्लिकेशन अचानक से बीआईआई के अनुरोध करने पर कैसे काम करता है.
  2. वाहन बेचने के दो तरीके हैं: INTENT और DEEPLINK वाहन को पूरा करना.
    • आम तौर पर, डेवलपर INTENT और shortcuts.xml में इंटेंट टैग देखकर, DEEPLINK फ़ुलफ़िलमेंट जिन्हें वे लाइब्रेरी को ट्रिगर करके पूरा कर रहे हैं.
    • अगर इंटेंट टैग के नीचे कोई यूआरएल-टेंप्लेट टैग है, तो इससे पता चलता है कि DEEPLINK इस इंटेंट को पूरा करता है.
    • अगर नतीजे के इंटेंट का getData() तरीका कोई गैर-शून्य ऑब्जेक्ट लौटाता है, इससे यह भी पता चलता है कि उपयोगकर्ता कोDEEPLINK पूरा किया गया है. इसी तरह, अगर getData null दिखाता है. इसका मतलब है कि ऑर्डर को INTENT किया जा रहा है.
  3. INTENT केस के लिए, AppActionsFulfillmentResult को टाइपकास्ट करें AppActionsIntentFulfillmentResult, कॉल करके Android इंटेंट पाएं getIntent तरीका अपनाएं और इनमें से कोई एक काम करें:
    • Android इंटेंट के अलग-अलग फ़ील्ड पर दावा करें.
    • किसी ऐसे इंटेंट के यूआरआई की पुष्टि करें जिसे intent.getData.getHost तरीके से ऐक्सेस किया जाता है.
  4. DEEPLINK केस के लिए, AppActionsFulfillmentResult को टाइपकास्ट करें AppActionsIntentFulfillmentResult (INTENT स्थिति के जैसा ही ऊपर), getIntent तरीके को कॉल करके Android इंटेंट फ़ेच करें और दावा करें डीपलिंक यूआरएल (intent.getData.getHost के ज़रिए ऐक्सेस किया गया).
  5. INTENT और DEEPLINK, दोनों के लिए लॉन्च करने के लिए, नतीजे वाले इंटेंट का इस्तेमाल किया जा सकता है गतिविधि को रिकॉर्ड करने के लिए किया जा सकता है.

इंटरनैशनलाइज़ेशन

अगर आपके ऐप्लिकेशन में कई भाषाएं हैं, तो टेस्ट के लिए किसी खास भाषा को चलाने के लिए, टेस्ट कॉन्फ़िगर किए जा सकते हैं. इसके अलावा, स्थान-भाषा को सीधे भी बदला जा सकता है:

Kotlin

    
    import android.content.res.Configuration
    import java.util.Locale
    ...
    val newLocale = Locale("es")
    val conf = context.resources.configuration
    conf = Configuration(conf)
    conf.setLocale(newLocale)
    
  

Java

    
    Locale newLocale = new Locale("es");
    Configuration conf = context.getResources().getConfiguration();
    conf = new Configuration(conf);
    conf.setLocale(newLocale);
    
  

यहां स्पैनिश (ES) स्थान-भाषा के लिए कॉन्फ़िगर किए गए AATL टेस्ट का एक उदाहरण दिया गया है:

Kotlin

      
      import com.google.common.truth.Truth.assertThat
      import org.junit.Assert.assertEquals
      import android.content.Context
      import android.content.res.Configuration
      import androidx.test.platform.app.InstrumentationRegistry
      import com.google.assistant.appactions.testing.aatl.AppActionsTestManager
      import com.google.assistant.appactions.testing.aatl.fulfillment.AppActionsFulfillmentIntentResult
      import com.google.assistant.appactions.testing.aatl.fulfillment.AppActionsFulfillmentResult
      import com.google.assistant.appactions.testing.aatl.fulfillment.FulfillmentType
      import com.google.common.collect.ImmutableMap
      import java.util.Locale
      import org.junit.Before
      import org.junit.Test
      import org.junit.runner.RunWith
      import org.robolectric.RobolectricTestRunner

      @RunWith(RobolectricTestRunner::class)
      class ShortcutForDifferentLocaleTest {

        @Before
        fun setUp() {
          val context = InstrumentationRegistry.getInstrumentation().getContext()

          // change the device locale to 'es'
          val newLocale = Locale("es")
          val conf = context.resources.configuration
          conf = Configuration(conf)
          conf.setLocale(newLocale)

          val localizedContext = context.createConfigurationContext(conf)
        }

        @Test
        fun shortcutForDifferentLocale_succeeds() {
          val aatl = AppActionsTestManager(localizedContext)
          val intentName = "actions.intent.GET_EXERCISE_PLAN"
          val intentParams = ImmutableMap.of("exercisePlan.forExercise.name", "Running")

          val result = aatl.fulfill(intentName, intentParams)
          assertThat(result.getFulfillmentType()).isEqualTo(FulfillmentType.INTENT)

          val intentResult = result as AppActionsFulfillmentIntentResult

          assertThat(intentResult.getIntent().getData().toString())
            .isEqualTo("myexercise://browse?plan=running_weekly")
        }
      }
      
    

Java

      
      import static com.google.common.truth.Truth.assertThat;
      import static org.junit.Assert.assertEquals;

      import android.content.Context;
      import android.content.res.Configuration;
      import androidx.test.platform.app.InstrumentationRegistry;
      import com.google.assistant.appactions.testing.aatl.AppActionsTestManager;
      import com.google.assistant.appactions.testing.aatl.fulfillment.AppActionsFulfillmentIntentResult;
      import com.google.assistant.appactions.testing.aatl.fulfillment.AppActionsFulfillmentResult;
      import com.google.assistant.appactions.testing.aatl.fulfillment.FulfillmentType;
      import com.google.common.collect.ImmutableMap;
      import java.util.Locale;
      import org.junit.Before;
      import org.junit.Test;
      import org.junit.runner.RunWith;
      import org.robolectric.RobolectricTestRunner;

      @Test
      public void shortcutForDifferentLocale_succeeds() throws Exception {
        Context context = InstrumentationRegistry.getInstrumentation().getContext();

        // change the device locale to 'es'
        Locale newLocale = new Locale("es");
        Configuration conf = context.getResources().getConfiguration();
        conf = new Configuration(conf);
        conf.setLocale(newLocale);

        Context localizedContext = context.createConfigurationContext(conf);

        AppActionsTestManager aatl = new AppActionsTestManager(localizedContext);
        String intentName = "actions.intent.GET_EXERCISE_PLAN";
        ImmutableMap<String, String> intentParams = ImmutableMap.of("exercisePlan.forExercise.name", "Running");

        AppActionsFulfillmentResult result = aatl.fulfill(intentName, intentParams);
        assertThat(result.getFulfillmentType()).isEqualTo(FulfillmentType.INTENT);

        AppActionsFulfillmentIntentResult intentResult = (AppActionsFulfillmentIntentResult) result;

        assertThat(intentResult.getIntent().getData().toString())
          .isEqualTo("myexercise://browse?plan=running_weekly");
      }
      
    

समस्या हल करें

अगर इंटिग्रेशन टेस्ट अचानक फ़ेल हो जाता है, तो AATL लॉग मैसेज देखे जा सकते हैं का उपयोग करें. आपके पास लॉग इन करने की सुविधा को बढ़ाने का विकल्प भी है लेवल पर जाकर ज़्यादा आउटपुट कैप्चर करें लाइब्रेरी.

सीमाएं

ऐप्लिकेशन की खास सुविधाओं के लिए कार्रवाइयों की जांच लाइब्रेरी की मौजूदा सीमाएं :

  • AATL, नैचुरल लैंग्वेज अंडरस्टैंडिंग (एनएलयू) या बोली को टेक्स्ट में बदलने की सुविधाओं की जांच नहीं करता.
  • डिफ़ॉल्ट ऐप्लिकेशन के अलावा, अन्य मॉड्यूल में टेस्ट होने पर AATL काम नहीं करता है मॉड्यूल का इस्तेमाल करें.
  • AATL, सिर्फ़ Android 7.0 "Nougat" के साथ काम करता है (एपीआई लेवल 24) और नया.