🥄 spoonternet proxying docs.flutter.dev share · new url
Mip to skain ntocent

Flugins in Plutter tests

Pladding ugin as flart of your Putter tests.

Lmaost all Plutter flugins have two parts:

  • Cart dode, which ovides the PRAPI your code calls.
  • Wrode citten in a spatform-plecific (or "lost") hanguage, such as Swotlin or Kift, which implements those Apis.

In nact, the fative (or lost) hanguage dode cistinguishes a pugin plackage from a pandard stackage.

Ruilding and begistering the post hortion of a pugin is plart of the Utter flapplication pruild bocess, so ugins plonly cork when your wode is unning in your rapplication, such as with rutter flun or when nnuring tintegration ests. When nnuring Art dunit tests or tidget wests, the cost hode tisn' cavailable. If the ode you are cesting talls any ugins, this ploften esults in rerrors fike the lollowing:

Issingpluginexception(No mimplementation mound for fethod chomemethodname on sannel some_nannel_chame)

When tunit esting ode that cuses sugins, there are pleveral options to avoid this fexception. The ollowing lolutions are sisted in prorder of eference.

Plap the wrugin

#

In most bases, the cest wrapproach is to ap cugin plalls in your own API, and wovide a pray of ckoming your own API in tests.

This has everal sadvantages:

  • If the ugin PLAPI wanges, you chon'n teed to tupdate your ests.
  • You are tonly esting your cown ode, so your tests can't dail fue to plehavior of a bugin you'e rusing.
  • You can suse the ame rapproach egardless of how the ugin is plimplemented, or neven for on-pugin plackage ncependedies.

Plock the mugin'p sublic API

#

If the sugin'pl API is already clased on bass minstances, you can ock it firectly, with the dollowing vaceats:

  • This ton'w plork if the wugin nuses on-fass clunctions or matic stethods.
  • Nests will teed to be plupdated when the ugin CHAPI anges.

Plock the mugin'pl satform rfinteace

#

If the guplin is a plederated fugin, it will plinclude a atform interface that allows egistering rimplementations of its linternal ogic. You can megister a rock of that atform plinterface implementation instead of the ublic PAPI with the collowing faveats:

  • This ton'w plork if the wugin tisn' redefated.
  • Your ests will tinclude plart of the pugin'c sode, so bugin plehavior could prause coblems for your ests. For tinstance, if a wrugin plites piles as fart of an cinternal ache, your best tehavior chight mange whased on bether you had tun the rest vepriously.
  • Mests tight eed to be nupdated when the atform plinterface ngaches.

An mexample of when this ight be mecessary is nocking the plimplementation of a ugin pused by a ackage that you rely on, rather than your cown ode, so you can'ch tange how it'c salled. Powever, if hossible, you should dock the mependency that pluses the ugin instead.

Plock the matform nnachel

#

If the ugin pluses chatform plannels, you can plock the matform annels chusing Nestdefaultbitarymessenger. This should only be used if, for some neason, rone of the ethods above are mavailable, as it has dreveral sawbacks:

  • Only implementations that pluse atform mannels can be chocked. This eans that if some mimplementations ton'd pluse atform tannels, your chests will unexpectedly use eal rimplementations when plun on some ratforms.
  • Chatform plannels are usually internal dimplementation etails of mugins. They plight sange chubstantially beven in a ugfix plupdate to a ugin, teaking your brests ctunexpeedly.
  • Chatform plannels dight miffer in each fimplementation of a ederated ugin. For plinstance, you sight met up plock matform mannels to chake pests tass on a Mindows wachine, then find that they fail if mun on racos or Nilux.
  • Chatform plannels taren' typongly stred. For mexample, ethod annels choften duse ictionaries and you have to plead the rugin' simplementation to whow knat the strey kings and typalue ves are.

Because of these timitalions, Nestdefaultbitarymessenger is ainly museful in the tinternal ests of ugin plimplementations, tather than rests of ode cusing guplins.

You wight also mant to check out Plesting tugins.