<< All versions

Skill v1.0.0

currentAutomated scan100/100
ishwormali/habbitpoint/testing
──Details
PublishedNovember 26, 2026 at 05:21 PM
Content Hashsha256:744350353de34bed...
Git SHA7e5fad399230
──Files
Files (1 file, 7.5 KB)
SKILL.md7.5 KBactive
SKILL.md · 284 lines · 7.5 KB

name: testing description: Writes and reviews Flutter/Dart tests. Use when writing unit tests, widget tests, or reviewing existing tests for correctness, structure, and naming conventions. metadata: version: "1.0.0"


Testing Skill

This skill defines how to write effective, meaningful Flutter and Dart tests.


1. Test Validity

Before writing or accepting a test, ask:

"Can this test actually fail if the real code is broken?"
  • Avoid tests that only confirm mocked/fake behavior that doesn't reflect real logic.
  • Avoid tests that confirm behavior guaranteed by the language, the standard library, or trivially obvious code that cannot fail unless the environment is broken.
  • Every test should be capable of catching a real regression.

2. Structure

Always use group() in test files — even when there is only one test. Name the group after the class under test:

dart
group('Counter', () {
test('value should start at 0', () {
final counter = Counter();
expect(counter.value, 0);
});
});

3. Naming

Name test cases using "should" to clearly describe the expected behavior:

dart
test('should emit updated list when item is added', () { ... });
test('should throw ArgumentError when input is negative', () { ... });

4. HabbitPoint Testing Examples

Model Testing: SkillItem

dart
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:habbitpoint/app/models/habit_models.dart';
import 'package:habbitpoint/app/theme/app_colors.dart';
group('SkillItem', () {
test('should calculate progress correctly', () {
const skill = SkillItem(
id: 'fitness',
name: 'Fitness',
level: 8,
currentXp: 240,
nextLevelXp: 300,
colors: [AppColors.orange, AppColors.red],
icon: Icons.fitness_center_rounded,
);
expect(skill.progress, 0.8);
});
test('should create new instance with copyWith', () {
const skill = SkillItem(
id: 'fitness',
name: 'Fitness',
level: 8,
currentXp: 240,
nextLevelXp: 300,
colors: [AppColors.orange, AppColors.red],
icon: Icons.fitness_center_rounded,
);
final updated = skill.copyWith(currentXp: 250);
expect(updated.currentXp, 250);
expect(updated.level, 8); // Unchanged
expect(skill.currentXp, 240); // Original unchanged
});
});

Provider Testing: activityLogsProvider

dart
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:habbitpoint/app/models/habit_models.dart';
import 'package:habbitpoint/app/riverpod/activity_logs_provider.dart';
group('activityLogsProvider', () {
test('should start with empty list', () {
final container = ProviderContainer();
expect(container.read(activityLogsProvider), isEmpty);
});
test('should add log to state', () {
final container = ProviderContainer();
final notifier = container.read(activityLogsProvider.notifier);
final log = ActivityLog(
id: '1',
label: 'Morning Run',
emoji: '🏃',
durationMinutes: 30,
moodLabel: 'Energized',
moodEmoji: '⚡',
xp: 10,
recordedAt: DateTime.now(),
colors: [Colors.orange],
);
notifier.addLog(log);
expect(container.read(activityLogsProvider), [log]);
});
test('should remove log by id', () {
final log1 = ActivityLog(
id: '1',
label: 'Morning Run',
emoji: '🏃',
durationMinutes: 30,
moodLabel: 'Good',
moodEmoji: '😊',
xp: 10,
recordedAt: DateTime.now(),
colors: [Colors.orange],
);
final log2 = ActivityLog(
id: '2',
label: 'Evening Study',
emoji: '📚',
durationMinutes: 60,
moodLabel: 'Focused',
moodEmoji: '🧠',
xp: 15,
recordedAt: DateTime.now(),
colors: [Colors.purple],
);
final container = ProviderContainer(
overrides: [
activityLogsProvider.overrideWithValue([log1, log2]),
],
);
container.read(activityLogsProvider.notifier).removeLog('1');
expect(container.read(activityLogsProvider), [log2]);
});
});

Widget Test: HomeScreen with Riverpod

dart
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:habbitpoint/app/models/habit_models.dart';
import 'package:habbitpoint/app/riverpod/tasks_provider.dart';
import 'package:habbitpoint/app/riverpod/skills_provider.dart';
import 'package:habbitpoint/app/screens/home_screen.dart';
import 'package:habbitpoint/app/theme/app_theme.dart';
group('HomeScreen', () {
testWidgets('should display quick actions from provider', (tester) async {
final mockTasks = [
const TaskItem(
id: '1',
title: 'It\'s your usual workout time',
xp: 5,
emoji: '🏃',
),
const TaskItem(
id: '2',
title: 'Quick 10-min stretch?',
xp: 1,
emoji: '🧘',
),
];
await tester.pumpWidget(
ProviderScope(
overrides: [
tasksProvider.overrideWithValue(mockTasks),
skillsProvider.overrideWithValue(const []),
],
child: MaterialApp(
theme: buildAppTheme(),
home: const HomeScreen(),
),
),
);
expect(find.text('It\'s your usual workout time'), findsOneWidget);
expect(find.text('Quick 10-min stretch?'), findsOneWidget);
});
testWidgets('should handle empty tasks gracefully', (tester) async {
await tester.pumpWidget(
ProviderScope(
overrides: [
tasksProvider.overrideWithValue(const []),
skillsProvider.overrideWithValue(const []),
],
child: MaterialApp(
theme: buildAppTheme(),
home: const HomeScreen(),
),
),
);
// Should render without crashing
expect(find.byType(HomeScreen), findsOneWidget);
});
});

Integration Test: Log Activity and See Updated Insights

dart
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:habbitpoint/app/models/habit_models.dart';
import 'package:habbitpoint/app/riverpod/activity_logs_provider.dart';
import 'package:habbitpoint/app/riverpod/insights_provider.dart';
import 'package:habbitpoint/app/screens/home_screen.dart';
import 'package:habbitpoint/app/theme/app_theme.dart';
group('Activity Logging Integration', () {
testWidgets('should update insights when activity is logged', (tester) async {
final container = ProviderContainer();
// Verify initial state (no activities, warning insight)
expect(container.read(activityLogsProvider), isEmpty);
final initialInsights = container.read(insightsProvider);
expect(
initialInsights.any((i) => i.type == InsightType.warning),
true,
);
// Log an activity
container.read(activityLogsProvider.notifier).addLog(
ActivityLog(
id: '1',
label: 'Morning Run',
emoji: '🏃',
durationMinutes: 30,
moodLabel: 'Energized',
moodEmoji: '⚡',
xp: 10,
recordedAt: DateTime.now(),
colors: [Colors.orange],
),
);
// Verify insights changed to positive
final updatedInsights = container.read(insightsProvider);
expect(
updatedInsights.any((i) => i.type == InsightType.positive),
true,
);
});
});
All versions