Skip to content

Conversation

@dudaa28
Copy link

@dudaa28 dudaa28 commented Jun 17, 2025

Unit Tests for MealDetailBloc

Unit Tests for MealDetailBloc with MC/DC Coverage and Nutritional Calculation Validations

Description

This PR adds a comprehensive suite of unit tests for the MealDetailBloc, ensuring validation of input fields, unit conversions, and nutritional calculations related to a meal.

The tests follow the Modified Condition/Decision Coverage (MC/DC) methodology to cover logical decisions affecting the app flow, focusing on:

  • Validation of required fields (selectedUnit and selectedTotalQuantity)
  • Correct conversion between measurement units (serving, oz, fl.oz, g)
  • Accurate calculation of nutritional values based on the converted quantity
  • Handling of parsing errors and invalid inputs
  • Scenarios with null or zero nutrient values
  • Correct conversion when dealing with decimal commas and large quantities

Changes Included

  • Tests validating empty or invalid inputs
  • Tests for quantity conversion based on the selected unit
  • Tests for accurate nutritional value calculations (energy, carbs, fat, protein)
  • Tests ensuring expected behavior with null, zero, and Brazilian decimal number formats
  • Additional tests for edge cases (very large quantities)
  • Test coverage ensuring MC/DC combinations are adequately tested

How to Test

  • Run flutter test in the project root to execute all unit tests.
  • Confirm all tests pass without errors.
  • Check coverage reports to ensure key conditions and decisions are covered.

Technical Context

  • Nutritional values are normalized per unit quantity (e.g., kcal per 1g)
  • Unit conversions use the UnitCalc utility class
  • Tests focus on calculation logic and input validation simulating user entries

Checklist

  • Code is commented and organized
  • Tests created for main use cases and edge cases
  • Tests pass in local environment
  • Documentation updated as needed

Related Issues

  • Not applicable

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant