You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
<divclass="platform-hinted " data-platform-hinted="data-platform-hinted"><divclass="content sourceset-dependent-content" data-active="" data-togglable=":burst:dokkaHtml/commonMain"><divclass="symbol monospace"><spanclass="token keyword">interface </span><ahref="index.html">TestInterceptor</a></div><pclass="paragraph">Intercepts the execution of a test function, including its <codeclass="lang-kotlin">@BeforeTest</code> and <codeclass="lang-kotlin">@AfterTest</code> functions.</p><pclass="paragraph">This sample creates a directory before a test runs and deletes it after.</p><divclass="sample-container"><pre><codeclass="block lang-kotlin" theme="idea">class TemporaryDirectory : TestInterceptor {<br> lateinit var path: Path<br> private set<br><br> override fun intercept(testFunction: TestFunction) {<br> path = createTemporaryDirectory(testFunction)<br> try {<br> testFunction()<br> } finally {<br> deleteTemporaryDirectory(path)<br> }<br> }<br>}</code></pre><spanclass="top-right-position"><spanclass="copy-icon"></span><divclass="copy-popup-wrapper popup-to-left"><spanclass="copy-popup-icon"></span><span>Content copied to clipboard</span></div></span></div><pclass="paragraph">Adopt an interceptor in your test by declaring a property of this type (or any subtype) and annotating it <codeclass="lang-kotlin">@InterceptTest</code>:</p><divclass="sample-container"><pre><codeclass="block lang-kotlin" theme="idea">class DocumentStorageTest {<br> @InterceptTest<br> val temporaryDirectory = TemporaryDirectory()<br><br> @Test<br> fun happyPath() {<br> val original = SampleData.document<br> DocumentWriter().write(original, temporaryDirectory.path)<br> val decoded = DocumentReader().read(temporaryDirectory.path)<br> assertThat(decoded).isEqualTo(original)<br> }<br>}</code></pre><spanclass="top-right-position"><spanclass="copy-icon"></span><divclass="copy-popup-wrapper popup-to-left"><spanclass="copy-popup-icon"></span><span>Content copied to clipboard</span></div></span></div></div></div>
<divclass="platform-hinted " data-platform-hinted="data-platform-hinted"><divclass="content sourceset-dependent-content" data-active="" data-togglable=":burst:dokkaHtml/commonMain"><divclass="symbol monospace"><spanclass="token keyword">interface </span><ahref="-test-interceptor/index.html">TestInterceptor</a></div><divclass="brief "><pclass="paragraph">Intercepts the execution of a test function, including its <codeclass="lang-kotlin">@BeforeTest</code> and <codeclass="lang-kotlin">@AfterTest</code> functions.</p></div></div></div>
0 commit comments