Welltested Docs
v2.x.x
v2.x.x
  • Documentation
    • Set up
    • Unit Tests
      • Annotation
      • Generate Tests
      • Save Tests
      • Good to Knows
        • Custom Testcases
        • Regenerate Bad Tests
        • The Batching Rule
    • FAQs
      • Paid Plans
      • Code Privacy
      • Support
      • Using with FVM
    • Testability Guidelines
Powered by GitBook
On this page
  • @Welltested()
  • Testcases
  • Exclude Methods

Was this helpful?

  1. Documentation
  2. Unit Tests

Annotation

Welltested uses annotations to mark the methods in your code to be tested. You can mark classes, extensions or top-level functions.

@Welltested()

You can mark the methods inside a class or an extension to be tested by adding @Welltested() annotation to the parent class/extension.

import 'package:welltested_annotation/welltested_annotation.dart';

@Welltested()
class Auth {
    Future<void> logInUser() {...}
    Future<void> logOutUser() {...}
}

In the above example, we will generate unit tests for logInUser and logOutUser methods of Auth class.

Annotating Top Level Functions:

If you've top-level functions in your code that do not belong to a class or extension method, you can annotate them directly.

import 'package:welltested_annotation/welltested_annotation.dart';

@Welltested()
double cartCalculator(List<CartItem> items, double tax) {...} // top-level function

Testcases

class Auth {
  @Testcases([
    "Ensure token is saved if login is successful",
    "Ensure existing token is cleared if login fails"
  ])
  Future<void> logInUser() {...}
  Future<void> logOutUser() {...}
}

Exclude Methods

By default, all methods in an annotated class are included. To exclude any method from testing, add their name to the excludedMethods list in the Welltested annotation.

@Welltested(excludedMethods: ['logOutUser'])
class Auth {
    Future<void> logInUser() {...}
    Future<void> logOutUser() {...}
}

In the above case, we will not create unit tests for logOutUser.

PreviousUnit TestsNextGenerate Tests

Last updated 1 year ago

Was this helpful?

Our testing AI examines and self creates smart exhaustive test cases for each function based on its use case and contextual code. However, you can specify your own custom test cases for a method by adding annotation to them.

@Testcases()