Flutter मोबाइल विकास · पाठ

एकीकरण परीक्षण

अपने अनुप्रयोग में अनेक विजेट और संपूर्ण उपयोगकर्ता प्रवाह के बीच सहभागिता को मान्य करने के लिए एकीकरण परीक्षण करें।

पाठ 2, कुल 4 में से11 चरण

एकीकरण परीक्षण, CoddyKit पर Flutter मोबाइल विकास का एक निःशुल्क पाठ है। यह 4 में से 2वाँ पाठ है। इस अध्ययन पथ के 3 तक कोई भी पाठ पूरा पढ़ना निःशुल्क है — इसके बाद CoddyKit PRO हर पाठ अनलॉक करता है, साथ ही अंतर्निर्मित कोड संपादक और चौबीसों घंटे एआई शिक्षक के साथ व्यावहारिक अभ्यास भी उपलब्ध कराता है। यह Flutter मोबाइल विकास सीखने के मार्ग का हिस्सा है और आपकी प्रगति वेब तथा CoddyKit ऐप पर सिंक होती रहती है। Flutter मोबाइल विकास पाठ्यक्रम में कुल 4 पाठ शामिल हैं।

Integration Tests क्या हैं

स्वागत है! इस lesson में हम integration testing को explore करेंगे, जो मजबूत Flutter apps बनाने का एक महत्वपूर्ण चरण है।

Integration tests यह जाँचते हैं कि आपके application के अलग-अलग हिस्से एक साथ कैसे काम करते हैं। इसे अपने app के साथ उपयोगकर्ता के पूरे flow का अनुकरण करने जैसा समझें, जिसमें logging in करना, navigation करना और actions करना शामिल है।

Integration Tests क्यों महत्वपूर्ण हैं

जहाँ widget tests (जिन्हें हमने पहले कवर किया था) अलग-अलग UI components पर ध्यान देते हैं, वहीं integration tests आपको यह भरोसा देते हैं कि उपयोगकर्ता के पूरे journeys सही ढंग से काम करते हैं।

  • वास्तविक परिस्थितियाँ: वास्तविक उपयोगकर्ता के व्यवहार का अनुकरण करती हैं।
  • Bugs जल्दी पकड़ना: उन समस्याओं को सामने लाती हैं जो केवल कई widgets या services के आपस में interact करने पर दिखाई देती हैं।
  • स्थिरता सुनिश्चित करना: पुष्टि करती हैं कि बदलाव मौजूदा features को खराब नहीं करते।

Integration Tests सेट करना

इन tests को सक्षम करने के लिए Flutter integration_test package का उपयोग करता है। इसकी सहायता से आप tests को सीधे किसी वास्तविक device या emulator पर चला सकते हैं, जिससे आपके app के व्यवहार का वास्तविक प्रतिनिधित्व मिलता है।

पहले, अपने pubspec.yaml file में dependencies और dev_dependencies दोनों के अंतर्गत integration_test dependency जोड़ें:

dependencies:
  flutter:
    sdk: flutter
  integration_test:
    sdk: flutter
dev_dependencies:
  flutter_test:
    sdk: flutter
  integration_test:
    sdk: flutter

Integration Test की संरचना

Integration tests में आमतौर पर दो मुख्य files होती हैं:

  • test driver, जो आमतौर पर test_driver/app_test.dart में होती है। यह file आपके integration tests चलाने के लिए environment तैयार करती है।
  • वास्तविक test suite, जो आमतौर पर integration_test/app_test.dart में होती है। यहीं आप अपने test का logic लिखते हैं।

Test Driver का Entry Point

test_driver/app_test.dart file सरल होती है। यह IntegrationTestWidgetsFlutterBinding को initialize करती है और test execution संभालने के लिए integrationDriver() को call करती है।

import 'package:integration_test/integration_test_driver.dart';

Future<void> main() async {
  IntegrationTestWidgetsFlutterBinding.ensureInitialized();
  await integrationDriver();
}

Integration Testing के लिए App

आइए integration test दिखाने के लिए एक सरल counter app बनाते हैं। ध्यान दें कि tests में जिन widgets को खोजकर interact करना है, उनमें हम Key जोड़ते हैं।

import 'package:flutter/material.dart';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatefulWidget {
  const MyApp({super.key});

  @override
  State<MyApp> createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  int _counter = 0;

  void _incrementCounter() {
    setState(() {
      _counter++;
    });
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Counter App',
      home: Scaffold(
        appBar: AppBar(title: const Text('Counter App')),
        body: Center(
          child: Column(
            mainAxisAlignment: MainAxisAlignment.center,
            children: <Widget>[
              const Text(
                'You have pushed the button this many times:',
              ),
              Text(
                '$_counter',
                key: const Key('counterText'),
                style: Theme.of(context).textTheme.headlineMedium,
              ),
            ],
          ),
        ),
        floatingActionButton: FloatingActionButton(
          key: const Key('incrementButton'),
          onPressed: _incrementCounter,
          tooltip: 'Increment',
          child: const Icon(Icons.add),
        ),
      ),
    );
  }
}

अपना Integration Test लिखना

अब आइए वास्तविक test को integration_test/app_test.dart में लिखते हैं। Animations और UI updates के लिए प्रतीक्षा करने हेतु हम tester.pumpAndSettle() का और उपयोगकर्ता की क्रिया का अनुकरण करने के लिए tester.tap() का उपयोग करेंगे।

import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:integration_test/integration_test.dart';

// Import your app's main file. 
// Replace 'my_app_name' with your actual package name.
import 'package:my_app_name/main.dart' as app;

void main() {
  IntegrationTestWidgetsFlutterBinding.ensureInitialized();

  group('Counter App Integration Tests', () {
    testWidgets('Verify counter increments on button tap', (tester) async {
      app.main(); // Start the application
      await tester.pumpAndSettle(); // Wait for the UI to build

      // Find the counter text and verify its initial value
      final counterTextFinder = find.byKey(const Key('counterText'));
      expect(counterTextFinder, findsOneWidget);
      expect(tester.widget<Text>(counterTextFinder).data, '0');

      // Find and tap the increment button
      final incrementButtonFinder = find.byKey(const Key('incrementButton'));
      await tester.tap(incrementButtonFinder);
      await tester.pumpAndSettle(); // Wait for state change & UI update

      // Verify the counter text has updated to 1
      expect(tester.widget<Text>(counterTextFinder).data, '1');

      // Tap again and verify it updates to 2
      await tester.tap(incrementButtonFinder);
      await tester.pumpAndSettle();
      expect(tester.widget<Text>(counterTextFinder).data, '2');
    });
  });
}

Integration Tests चलाना

अपने integration tests चलाने के लिए आप अपने project की root directory से flutter drive command का उपयोग करेंगे। सुनिश्चित करें कि Android emulator/device या iOS simulator/device चल रहा हो।

यह command Flutter को आपके test driver का उपयोग करके आपके app के विरुद्ध integration test suite चलाने के लिए कहती है।

flutter drive \
  --driver=test_driver/app_test.dart \
  --target=integration_test/app_test.dart

उन्नत Interactions

Integration tests कई screens पर जटिल user flows का अनुकरण कर सकते हैं। आप:

  • Text दर्ज कर सकते हैं: tester.enterText(find.byType(TextField), 'Hello'); का उपयोग करें।
  • Scroll कर सकते हैं: widgets को दिखाई देने वाले क्षेत्र में लाने के लिए tester.scrollUntilVisible() का उपयोग करें।
  • Navigate कर सकते हैं: Navigator.push() या Navigator.pop() चलाने वाले buttons पर tap करें और screen में हुए बदलावों की पुष्टि करें।

मजबूत widget identification के लिए हमेशा Key का उपयोग करें, विशेषकर dynamic UIs या एक जैसे कई widgets के साथ काम करते समय।

त्वरित जाँच

Flutter development में integration tests का उपयोग करने के प्रमुख लाभों में से कौन-से हैं?

पुनरावलोकन: Integration Testing

बहुत अच्छा! आपने Flutter में integration testing के बारे में सीख लिया है। हमने कवर किया:

  • Integration tests क्या हैं और app की stability के लिए वे क्यों महत्वपूर्ण हैं।
  • integration_test package कैसे सेट किया जाता है।
  • Integration tests की structure और उन्हें लिखने का तरीका।
  • flutter drive का उपयोग करके tests कैसे चलाए जाते हैं।

Integration tests यह भरोसा देते हैं कि आपके app के features उसी तरह सहजता से एक साथ काम करते हैं, जैसा उपयोगकर्ता उन्हें अनुभव करेगा।

शुरुआत निःशुल्क

एआई शिक्षक के साथ Dart सीखें — निःशुल्क

अपने ब्राउज़र में वास्तविक कोड लिखें और चलाएँ, चौबीसों घंटे एआई शिक्षक से तुरंत सहायता पाएँ, और वेब या ऐप पर वहीं से शुरू करें जहाँ आपने छोड़ा था।

पाठ्यक्रम
22
पाठ
88

अक्सर पूछे जाने वाले प्रश्न

क्या “एकीकरण परीक्षण” पाठ निःशुल्क है?

हाँ — Flutter मोबाइल विकास अध्ययन पथ के 3 तक कोई भी पाठ, जिसमें “एकीकरण परीक्षण” भी शामिल है, यहाँ वेब पर पूरा पढ़ना निःशुल्क है। इसके बाद CoddyKit PRO हर पाठ अनलॉक करता है, साथ ही अंतर्निर्मित कोड संपादक और चौबीसों घंटे एआई शिक्षक के साथ इंटरैक्टिव अभ्यास भी उपलब्ध कराता है। Flutter मोबाइल विकास पाठ्यक्रम में कुल 4 पाठ शामिल हैं।

“एकीकरण परीक्षण” में मैं क्या सीखूँगा?

अपने अनुप्रयोग में अनेक विजेट और संपूर्ण उपयोगकर्ता प्रवाह के बीच सहभागिता को मान्य करने के लिए एकीकरण परीक्षण करें। आप ब्राउज़र में सीधे चलाए जाने वाले व्यावहारिक कोड के साथ Flutter मोबाइल विकास का अभ्यास करते हैं, और पाठ पूरा करते समय 24/7 एआई ट्यूटर आपके प्रश्नों के उत्तर देता है।

क्या Flutter मोबाइल विकास शुरू करने के लिए मुझे किसी अनुभव की आवश्यकता है?

पहले के अनुभव की आवश्यकता नहीं है। CoddyKit पर Flutter मोबाइल विकास शुरुआती से लेकर उन्नत शिक्षार्थियों तक सभी के लिए व्यवस्थित किया गया है, इसलिए आप यहीं से या शुरुआत से सीखना शुरू कर सकते हैं और अपनी गति से आगे बढ़ सकते हैं। यह 4 में से 2वाँ पाठ है।

“एकीकरण परीक्षण” पाठ पूरा करने में कितना समय लगता है?

CoddyKit का अधिकांश पाठ लगभग 5–10 मिनट में पूरा हो जाता है। हर पाठ छोटा और संवादात्मक है, इसलिए आप लगातार प्रगति करते हैं और वेब या ऐप पर वहीं से सीखना जारी रख सकते हैं जहाँ आपने छोड़ा था।

क्या मैं इस Flutter मोबाइल विकास पाठ में कोड लिख और चला सकता हूँ?

हाँ। हर Flutter मोबाइल विकास पाठ में एक अंतर्निर्मित कोड संपादक शामिल है, जिससे आप सीधे अपने ब्राउज़र में वास्तविक कोड लिख और चला सकते हैं और तुरंत एआई प्रतिक्रिया पा सकते हैं—स्थानीय सेटअप की आवश्यकता नहीं है।

इस पाठ्यक्रम के सभी पाठ

  1. विजेट परीक्षण के सिद्धांत
  2. एकीकरण परीक्षण
  3. डीबगिंग उपकरण और तकनीकें
  4. यूनिट टेस्टिंग और मॉकिंग
← Flutter मोबाइल विकास पर वापस जाएँ