queendevelopers / Flutter-Counter-Example-With-Tests

"Flutter Counter Example with Tests Explore Flutter testing with this counter app. Includes unit, widget, and integration tests, along with golden tests for UI. Track code coverage with lcov reports. Ideal for learning effective testing in Flutter."

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Overview

The Counter App is a simple Flutter application that allows users to increment and decrement a counter value. It serves as a basic example for understanding Flutter app development and state management.

Features

  • Increment and decrement buttons for modifying the counter value.
  • Display of the current counter value.

Installation

  1. Clone the repository:
    git clone https://github.com/queendevelopers/flutter-counter-example-with-test.git
    
  2. Navigate to the project directory:
    cd counter
    
  3. Install dependencies
    flutter pub get
    
  4. Run the app flutter run
    flutter run
    
  5. Run test
    flutter test
    
  6. Run Integration test
    flutter driver --target=test_driver/main_app.dart --driver=test_driver/main_app_test.dart
    
  7. Generate screenshot in target devices
    TARGET_PLATFORM=ios flutter driver --target=test_driver/main_app.dart --driver=test_driver/main_app_test.dart
    
    TARGET_PLATFORM=chrome flutter driver --target=test_driver/main_app.dart --driver=test_driver/main_app_test.dart -d chrome # Make sure to run webdriver first.
    

Project files

  • main.dart: counter application
  • counter.dart: increment and decrement method
  • .vscode/launch.json: vscode launch configuration for application, unit test, widget test and integration test.
  • test/unit/counter_test: unit test.
  • test/wiget/counter_widget_test: widget & golden test
  • test_driver: integration test and screenshot extension method.
  • .github: configuration for codemagic.
  • coverage: generated codecoverage from lcov.

Unit and widget test screenshot Integration test

Code coverage

  • We have 100% code coverage for counter application (also demonstrates ignore file for main function). You can open code coverage page by using command on root for the project :
    open coverage/html/index.html
    

code coverage screenshot

Codemagic

  • Codemagic setup is required to work the github continuos integration and deployment.
  • If you manage to setup on your personal repo then check Run only test and Android. (iOS build won't work util you add certificates)
  • Also, for flutter integration test arguments, you need to replace with following command:
    driver --target=test_driver/main_app.dart --driver=test_driver/main_app_test.dart
    

code magic screenshot code magic screenshot

About

"Flutter Counter Example with Tests Explore Flutter testing with this counter app. Includes unit, widget, and integration tests, along with golden tests for UI. Track code coverage with lcov reports. Ideal for learning effective testing in Flutter."


Languages

Language:HTML 46.3%Language:C++ 16.7%Language:CSS 15.9%Language:CMake 12.7%Language:Dart 4.5%Language:Ruby 2.1%Language:Swift 1.2%Language:C 0.6%Language:Kotlin 0.1%Language:Objective-C 0.0%