Hacktoberfest 2026 : les issues que les mainteneurs ont marquées pour octobre, ouvertes et accessibles aux débutants. Parcourir les issues Hacktoberfest

Support explicitly disposing test dependencies

Ouverte
#95 0 commentaires 0 réactions 0 personnes assignées Voir sur GitHub

Personne n'a encore pris cette issue.

Évaluation

Difficulté
5/5
Temps estimé
Plus d'une semaine
Accessibilité débutants
30/100
Type d'issue
Fonctionnalité
Clarté
À clarifier
Activité
Calme
Stack technique
csharp
Domaine
testing

Piste de recherche

Commencez par examiner les options Add(Async)TestBlock et Add(Async)FinallyBlocks, puis étudiez le comportement de TestCase décrit dans l’issue. Une modification aboutie doit établir et documenter une approche de libération qui nettoie de manière fiable les contextes de navigateur Playwright propres à chaque test et éventuellement les navigateurs, sans masquer les dépendances.

Rédigé par le modèle d'indexation à partir du texte de l'issue.

Description

Traditionally, we don't use dependency injection for objects that need to be explicitly disposed (e.g. rest clients that we want to stick around for all tests to reuse.) They are handled as part of the unit test method lifecycle using unit test setup/teardown. This works fine in most cases, but has always been kinda shaky as it can easily break the TestFramework concept of not hiding dependencies away.

However, we recently ran into a situation migrating a project from Selenium to Playwright, and had issues with how that project was managing disposable objects. Hooking playwright into the existing framework would involve a lot of effort, but Injecting the playwright disposables into DI doesn't properly work as we declare test dependencies as singletons so it doesn't reliably get cleaned up at the end of a test (playwright's instance is static, that may be the difficulty here.)

Consideration: For Playwright specifically, the parent Playwright object is okay to leave around for the entire test run, but we really want to destroy the browser context (and possibly the browser itself) between each run so that we're NOT just adding more open browsers on longer test runs.

Some possible fixes:

  • Do nothing. Create a finally block to dispose the context (and possibly browser)
    • Pro: It's easy and visible
    • Con: for new projects someone will need to know to do this
      • Possible mitigation:
        • Update documentation and provide an example in the Examples project
        • Write an analyzer that throws an informational message (already have other items that would be good for an analyzer, e.g. test blocks with no execute method.)
  • Change or add Add(Async)TestBlock and Add(Async)FinallyBlocks that use a scoped lifetime.
    • Pro: automagically handled
    • Con: Could be unintentional behavior changes if we update existing methods, or would require someone to know the difference between scoped and singleton lifetimes (or what's disposable and what isn't) if we add new methods, which breaks the concept of not requiring and automated tester to know those specifics
      • Possible mitigation:
        • Four unique methods, something like Add(Async)DisposableTest(Finally)Block
        • Just change the existing methods to use scoped instead of singleton
        • Update the TestCase behavior to search through the container for any singletons that implement IDisposable and explicitly call them before going into the logic to throw any exceptions that occurred
Langage dominant
C#
Étoiles
1
Forks
1
Métriques de merge des PR
Aucune PR mergée en 30 j

Préparer son environnement

Par où commencer

  1. Lisez l'issue en entier, puis le guide de contribution du projet.
  2. Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
  3. Forkez le dépôt et travaillez sur une branche.
  4. Ouvrez une pull request qui référence le numéro de l'issue.

Autres issues de IntelliTect/TestTools.TestFramework

Toutes les issues de IntelliTect/TestTools.TestFramework

Issues similaires

Plus d'issues C#

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.