{"id":28582,"date":"2026-11-26T19:55:44","date_gmt":"2026-11-26T19:55:44","guid":{"rendered":"https:\/\/capskip.com\/?p=28582"},"modified":"2026-11-26T19:55:44","modified_gmt":"2026-11-26T19:55:44","slug":"nunit-captcha-csharp","status":"publish","type":"post","link":"https:\/\/capskip.com\/zh\/nunit-captcha-csharp\/","title":{"rendered":"\u5728 C# \u4e2d\u7528 CapSkip .NET SDK \u7f16\u5199 NUnit \u9a8c\u8bc1\u7801\u6d4b\u8bd5"},"content":{"rendered":"<p>An NUnit CAPTCHA test should get its token from one CapSkip client built in a SetUpFixture, with a fresh solve inside each test, since a token is good once. Put CancelAfter on the test and give the SDK the test&#8217;s cancellation token, so a stuck solve ends with the test; NUnit refuses to run a test that carries the old Timeout attribute. LevelOfParallelism then sets how many solves overlap, on .NET 10 or .NET 8.<\/p>\n<h2 style=\"font-size:1.6rem;line-height:1.35;\">What you need<\/h2>\n<ul>\n<li>A Windows PC that runs CapSkip with its reCAPTCHA solver switched on. Your first launch of CapSkip is described in the <a href=\"https:\/\/capskip.com\/setup-guide\/\">setup guide<\/a>.<\/li>\n<li>The .NET 8 SDK or later. NUnit 5.0.0 ships builds for net8.0, net10.0 and .NET Framework 4.6.2 only: a net6.0 project restored it, then failed to build with CS0246. I ran SDK 10.0.100 on runtimes 10.0.0 and 8.0.27 with NUnit 5.0.0, NUnit3TestAdapter 6.3.1, Microsoft.NET.Test.Sdk 18.12.0 and CapSkip 1.8.0.<\/li>\n<li>A staging form you control, with a checkbox reCAPTCHA v2 widget and a CSRF field.<\/li>\n<li>Somewhere for the tests to reach CapSkip. Local mode listens on 127.0.0.1, so only the same device can reach it, while Server mode listens on your network or public IP. The mode is chosen in the <a href=\"https:\/\/capskip.com\/setup-guide\/#connection-settings\">connection settings<\/a>.<\/li>\n<\/ul>\n<p>Nothing below ran against a real CapSkip or a real site. I drove the genuine NUnit and CapSkip packages against a mock CapSkip API and a mock sign-up page, which decide how long a solve takes, how many run at once and when the form is accepted.<\/p>\n<h2 style=\"font-size:1.6rem;line-height:1.35;\">Build the suite in four steps<\/h2>\n<h3 style=\"font-size:1.3rem;line-height:1.4;\">Step 1: create the test project<\/h3>\n<p>On SDK 10.0.100 the nunit template accepts only net10.0 and pins NUnit 4.3.2, NUnit3TestAdapter 5.0.0 and Microsoft.NET.Test.Sdk 17.14.0, so the block adds the current packages and deletes the sample test. For .NET 8, change TargetFramework in the project file afterwards. You don&#8217;t need a global.json: plain dotnet test ran the adapter through VSTest, with no build warnings. The template adds a global using, so no file below imports NUnit.Framework.<\/p>\n<div data-no-translation>\n<pre data-enlighter-language=\"bash\" class=\"EnlighterJSRAW\"># The built-in template pins older packages, so add the current ones.\ndotnet new nunit -n CapSkipTests -f net10.0\ncd CapSkipTests\nrm UnitTest1.cs          # the template's sample test; delete it\ndotnet add package NUnit\ndotnet add package NUnit3TestAdapter\ndotnet add package Microsoft.NET.Test.Sdk\ndotnet add package CapSkip<\/pre>\n<\/div>\n<h3 style=\"font-size:1.3rem;line-height:1.4;\">Step 2: one CapSkip client for the whole run<\/h3>\n<p>NUnit has no constructor injection, so shared objects live in statics, and a SetUpFixture builds them: its OneTimeSetUp runs once before the first fixture in its namespace, so keep every test class in CapSkipTests. The block reads the CapSkip settings from the environment, because the SDK doesn&#8217;t, builds one client and checks whether anything listens with a TCP connect, which sends no solve job. Save it as CapSkipSetup.cs in the CapSkipTests folder.<\/p>\n<div data-no-translation>\n<pre data-enlighter-language=\"csharp\" class=\"EnlighterJSRAW\">\/\/ CapSkipSetup.cs\nusing System.Net.Sockets;\nusing CapSkip;\n\nnamespace CapSkipTests;\n\n\/\/ No tests in here: a SetUpFixture runs once before the first and once\n\/\/ after the last fixture in its namespace.\n[SetUpFixture]\npublic class CapSkipSetup\n{\n    \/\/ The SDK never reads CAPSKIP_* itself, so read them here.\n    private static string Env(string name, string fallback) =&gt;\n        Environment.GetEnvironmentVariable(name) ?? fallback;\n\n    public static CapSkipClient Solver { get; private set; } = null!;\n    public static string SiteUrl { get; private set; } = &quot;&quot;;\n\n    [OneTimeSetUp]\n    public async Task BuildClientAsync()\n    {\n        var host = Env(&quot;CAPSKIP_HOST&quot;, &quot;127.0.0.1&quot;);\n        var port = int.Parse(Env(&quot;CAPSKIP_PORT&quot;, &quot;8080&quot;));\n        SiteUrl = Env(&quot;STAGING_URL&quot;, &quot;https:\/\/staging.example.com&quot;);\n        Solver = new CapSkipClient(\n            apiKey: Env(&quot;CAPSKIP_API_KEY&quot;, &quot;capskip&quot;), host: host, port: port);\n\n        \/\/ A TCP connect asks &quot;is anything listening?&quot; and sends no solve job.\n        using var tcp = new TcpClient();\n        using var timeout = new CancellationTokenSource(TimeSpan.FromSeconds(1));\n        try { await tcp.ConnectAsync(host, port, timeout.Token); }\n        catch (Exception e) when (e is SocketException or OperationCanceledException)\n        {\n            var reason = $&quot;CapSkip is not listening on {host}:{port}&quot;;\n            if (Env(&quot;CAPSKIP_REQUIRED&quot;, &quot;&quot;) == &quot;1&quot;) Assert.Fail(reason); \/\/ CI: fail the run\n            Assert.Ignore(reason);                                       \/\/ desk: skip it\n        }\n    }\n}<\/pre>\n<\/div>\n<p>With CapSkip closed, all three tests came out Skipped with the reason and the exit code was 0. With CAPSKIP_REQUIRED set to 1 they failed and the exit code was 1, which suits a CI job. One client was safe to share: fourteen solves went through it below.<\/p>\n<h3 style=\"font-size:1.3rem;line-height:1.4;\">Step 3: the staging helper and the test<\/h3>\n<p>The helper is not part of CapSkip. It reads the sitekey and CSRF token from the page and posts the form, adding a Referer header because HttpClient sends none and a strict Django site over HTTPS refuses the form post without it. Each test builds its own helper, so parallel tests share no cookies. Save the helper as StagingForm.cs and the test as SignupTests.cs, in the same folder.<\/p>\n<div data-no-translation>\n<pre data-enlighter-language=\"csharp\" class=\"EnlighterJSRAW\">\/\/ StagingForm.cs\nusing System.Net;\nusing System.Text.RegularExpressions;\n\nnamespace CapSkipTests;\n\npublic sealed record SignupPage(string Url, string SiteKey, string Csrf);\n\n\/\/ One instance per test: its HttpClient keeps this test's cookies only.\npublic sealed class StagingForm(string baseUrl) : IDisposable\n{\n    private readonly HttpClient _http = new();\n\n    public async Task&lt;SignupPage&gt; OpenAsync(string path, CancellationToken ct)\n    {\n        var url = baseUrl + path;\n        var html = await _http.GetStringAsync(url, ct);\n        return new SignupPage(url,\n            Regex.Match(html, &quot;data-sitekey=\\&quot;([^\\&quot;]+)\\&quot;&quot;).Groups[1].Value,\n            Regex.Match(html, &quot;name=\\&quot;csrfmiddlewaretoken\\&quot; value=\\&quot;([^\\&quot;]+)\\&quot;&quot;).Groups[1].Value);\n    }\n\n    public async Task&lt;(HttpStatusCode Status, string Body)&gt; PostAsync(\n        SignupPage page, string token, CancellationToken ct)\n    {\n        using var request = new HttpRequestMessage(HttpMethod.Post, page.Url)\n        {\n            Content = new FormUrlEncodedContent(new Dictionary&lt;string, string&gt;\n            {\n                [&quot;csrfmiddlewaretoken&quot;] = page.Csrf,\n                [&quot;username&quot;] = &quot;ci-user&quot;,\n                [&quot;g-recaptcha-response&quot;] = token,\n            }),\n        };\n        request.Headers.Referrer = new Uri(page.Url); \/\/ HttpClient sends none\n        using var response = await _http.SendAsync(request, ct);\n        return (response.StatusCode, await response.Content.ReadAsStringAsync(ct));\n    }\n\n    public void Dispose() =&gt; _http.Dispose();\n}<\/pre>\n<\/div>\n<p>The test solves its own CAPTCHA and checks the reply. CancelAfter is in milliseconds and applies to each attempt. The token from TestContext.CurrentContext.CancellationToken goes to every awaited call, the solve included. Adjust welcome and the field names to match your form.<\/p>\n<div data-no-translation>\n<pre data-enlighter-language=\"csharp\" class=\"EnlighterJSRAW\">\/\/ SignupTests.cs\nusing System.Net;\n\nnamespace CapSkipTests;\n\npublic class SignupTests\n{\n    \/\/ Data only. NUnit runs a source when it lists the tests, long\n    \/\/ before any test starts, so never solve in here.\n    public static IEnumerable&lt;TestCaseData&gt; Pages()\n    {\n        yield return new TestCaseData(&quot;\/signup&quot;).SetName(&quot;plain sign-up&quot;);\n        yield return new TestCaseData(&quot;\/signup?plan=pro&quot;).SetName(&quot;pro plan&quot;);\n        yield return new TestCaseData(&quot;\/signup?plan=team&quot;).SetName(&quot;team plan&quot;);\n    }\n\n    [TestCaseSource(nameof(Pages)), CancelAfter(120_000)] \/\/ ms, for each attempt\n    public async Task Page_accepts_a_fresh_token(string path)\n    {\n        var ct = TestContext.CurrentContext.CancellationToken;\n        using var form = new StagingForm(CapSkipSetup.SiteUrl);\n\n        var page = await form.OpenAsync(path, ct);\n        var solved = await CapSkipSetup.Solver.RecaptchaAsync(\n            page.SiteKey, page.Url, cancellationToken: ct);\n        var (status, body) = await form.PostAsync(page, solved.Code, ct);\n\n        Assert.That(body, Does.Contain(&quot;welcome&quot;)); \/\/ on failure NUnit prints the reply\n        Assert.That(status, Is.EqualTo(HttpStatusCode.OK));\n    }\n}<\/pre>\n<\/div>\n<p>The TestCaseSource holds data only, because NUnit calls a source when it lists the tests. A source that solved a CAPTCHA started a solve when I only listed the tests and put the 300-character token into the test&#8217;s name. In a run it ran once, before the tests, and a reCAPTCHA token expires after about two minutes (see the <a href=\"https:\/\/capskip.com\/recaptcha-token-expiration\/\">guide to reCAPTCHA token expiration<\/a>). Solve in the test body.<\/p>\n<h3 style=\"font-size:1.3rem;line-height:1.4;\">Step 4: run it<\/h3>\n<p>Set the variables in PowerShell, then call dotnet test from inside the project folder. The console logger at normal verbosity lists each case. A passing run shows three Passed lines, each about a second against the mock.<\/p>\n<div data-no-translation>\n<pre data-enlighter-language=\"bash\" class=\"EnlighterJSRAW\"># PowerShell. The setup fixture reads these; unset ones fall back to defaults.\n$env:CAPSKIP_HOST     = &quot;127.0.0.1&quot;   # a Server mode machine: its LAN IP\n$env:CAPSKIP_PORT     = &quot;8080&quot;\n$env:CAPSKIP_API_KEY  = &quot;capskip&quot;\n$env:STAGING_URL      = &quot;https:\/\/staging.example.com&quot;\ndotnet test --logger &quot;console;verbosity=normal&quot;<\/pre>\n<\/div>\n<p>For a CI job only, set this optional line as well. With it set, a run that cannot reach CapSkip fails instead of skipping.<\/p>\n<div data-no-translation>\n<pre data-enlighter-language=\"bash\" class=\"EnlighterJSRAW\"># Optional, CI only: fail the run when CapSkip is not listening.\n$env:CAPSKIP_REQUIRED = &quot;1&quot;<\/pre>\n<\/div>\n<h2 style=\"font-size:1.6rem;line-height:1.35;\">CancelAfter stops the test, but the token has to reach the solve<\/h2>\n<p>Timeout is obsolete: the build warns with CS0618 because .NET no longer supports aborting threads. Worse, a test with it does not run: it failed after 2 milliseconds with TargetFramework doesn&#8217;t support timeout on tests, and the mock saw no job. CancelAfter aborts nothing either; it cancels the test&#8217;s token and relies on your code to notice. The table uses a 20 second solve and a CancelAfter of 3000; the rows were the same on net8.0.<\/p>\n<table>\n<thead>\n<tr>\n<th>Which calls got the token<\/th>\n<th>Result<\/th>\n<th>Test time<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>All of them, the solve included<\/td>\n<td>Failed: Test exceeded CancelAfter value of 3000ms<\/td>\n<td>3 s<\/td>\n<\/tr>\n<tr>\n<td>The page calls but not the solve<\/td>\n<td>Failed with the same message, after the solve ended<\/td>\n<td>21 to 22 s<\/td>\n<\/tr>\n<tr>\n<td>No call got the token<\/td>\n<td>Passed<\/td>\n<td>about 21 to 22 s<\/td>\n<\/tr>\n<tr>\n<td>All, with the submit held for 20 s<\/td>\n<td>Failed: CapSkip.NetworkException, The operation was canceled<\/td>\n<td>3 s<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>So the token has to reach the solve. In the third row nothing observed it, and a test far over its limit passed. In the fourth the SDK raised its own NetworkException, as it does when the cancel lands during the submit. Outside CancelAfter the token can never be cancelled, so passing it is harmless.<\/p>\n<p>The SDK has a second, independent limit: the recaptchaTimeout constructor option, in seconds. It defaults to 300, above the 120_000 ms CancelAfter here, and throws CapSkip.TimeoutException. With it set to 3, a 20 second solve and CancelAfter left at 120000, the test failed at 3 seconds with that exception on both runtimes. Neither limit cancels the job inside CapSkip, since the SDK sends only submits and polls. In the mock the job kept running for the rest of its 20 seconds after the test failed, and the polls stopped. Unverified on the real app: a cancelled test may hold a CapSkip thread until its solve ends, which counts against the Max. Threads cap below.<\/p>\n<h2 style=\"font-size:1.6rem;line-height:1.35;\">NUnit runs one test at a time: cap the solves with LevelOfParallelism<\/h2>\n<p>NUnit runs tests one after another unless you opt in, where <a href=\"https:\/\/capskip.com\/xunit-captcha-csharp\/\">xUnit<\/a> overlaps classes from the start. Put Parallelizable on the assembly, a fixture or a test: Fixtures lets classes overlap, Children lets tests inside one class overlap, and All allows both. The worker count is then your cap on solves, since a test that awaited a solve held its worker; a cap of 4 never put more than 4 solves in flight. Save this block as AssemblyInfo.cs.<\/p>\n<div data-no-translation>\n<pre data-enlighter-language=\"csharp\" class=\"EnlighterJSRAW\">\/\/ AssemblyInfo.cs\n\/\/ Run every test and fixture side by side, on at most 4 worker threads.\n[assembly: Parallelizable(ParallelScope.All)]\n[assembly: LevelOfParallelism(4)]<\/pre>\n<\/div>\n<p>Here are 14 cases against the mock, each solve held for 3 seconds. The time is the Total time line of dotnet test; in the one-at-a-time run each test took about 3.8 seconds, the hold plus the page request, the SDK&#8217;s polling gap and the form post. The runs on net8.0 gave the same peaks and times within half a second.<\/p>\n<table>\n<thead>\n<tr>\n<th>Setting<\/th>\n<th>Total time<\/th>\n<th>Peak solves in the mock<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>No attribute (the default)<\/td>\n<td>54.1 s<\/td>\n<td>1<\/td>\n<\/tr>\n<tr>\n<td>All scope and a cap of 4 (the block above)<\/td>\n<td>16.2 s<\/td>\n<td>4<\/td>\n<\/tr>\n<tr>\n<td>All scope, no cap<\/td>\n<td>8.9 s<\/td>\n<td>10 running, 14 started<\/td>\n<\/tr>\n<tr>\n<td>The block above plus a command-line cap of 2<\/td>\n<td>27.7 s<\/td>\n<td>2<\/td>\n<\/tr>\n<tr>\n<td>A command-line cap of 2 and no attribute<\/td>\n<td>54.3 s<\/td>\n<td>1<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>With no cap, all 14 solves started at once on this 24-processor PC. The mock allows 10 at a time, as the reCAPTCHA Max. Threads setting in CapSkip does by default, so 4 waited inside the mock, against the Wait Timeout setting. A cap below that limit moves the waiting into your test process. This command sets the worker count with no rebuild.<\/p>\n<div data-no-translation>\n<pre data-enlighter-language=\"bash\" class=\"EnlighterJSRAW\"># Same cap from the command line: no rebuild, and it overrides the attribute.\ndotnet test -- NUnit.NumberOfTestWorkers=2<\/pre>\n<\/div>\n<p>The command-line count beat the attribute (peak 2 against 4), but does not switch parallelism on alone: with no attribute, a count of 2 still gave a peak of 1. The <a href=\"https:\/\/docs.nunit.org\/articles\/nunit\/writing-tests\/attributes\/parallelizable.html\" rel=\"noopener nofollow\" target=\"_blank\">NUnit Parallelizable documentation<\/a> lists the scopes.<\/p>\n<h2 style=\"font-size:1.6rem;line-height:1.35;\">Retry an NUnit CAPTCHA test: the whole test, not the token<\/h2>\n<p>Retry runs the whole test method again, so a retry solves again, and that suits a CAPTCHA, because a token the site burnt on a failed post is useless. It costs a solve, and maybe more: the CapSkip 3.1.0 changelog says every CAPTCHA type gets one automatic retry by default (the Retries setting turns it off), so a failed solve may already have been retried inside the app. I did not test that. In the mock the site burnt the first token and refused the form, and without Retry the test failed. With a Retry of 3 it passed on the second attempt after two solves, and when the site burnt two tokens, on the third after three: the number counts attempts in all. Solving once in a OneTimeSetUp instead fails every attempt: the site burnt that token on the first post, the later attempts were told it was already used, and the mock saw one solve.<\/p>\n<p>A thrown exception is not retried by default. With the first two solves ending in ERROR_CAPTCHA_UNSOLVABLE, a plain Retry of 3 failed after one attempt with CapSkip.ApiException, and the mock saw one job. The RetryExceptions property adds types to retry. Replace the attribute line in SignupTests.cs with this snippet and add a using line for CapSkip. The same run then passed on the third attempt after three solves.<\/p>\n<div data-no-translation>\n<pre data-enlighter-language=\"csharp\" class=\"EnlighterJSRAW\">\/\/ SignupTests.cs (snippet: replace the attribute line; add &quot;using CapSkip;&quot;)\n\/\/ A retry runs the whole method again, so it solves again.\n[TestCaseSource(nameof(Pages)), CancelAfter(120_000),\n Retry(3, RetryExceptions = new[] { typeof(ApiException) })]<\/pre>\n<\/div>\n<p>RetryExceptions matches the type, not the message. The mock refused a wrong key with ERROR_KEY_DOES_NOT_EXIST, also an ApiException, and this attribute made three attempts at it, where a plain Retry made one. CancelAfter measures each attempt: a Retry of 2 with a CancelAfter of 5000 passed after 7 seconds in all. The console logger showed a retried test as one plain Passed line; I checked no other logger.<\/p>\n<h2 style=\"font-size:1.6rem;line-height:1.35;\">Common errors with NUnit CAPTCHA tests<\/h2>\n<table>\n<thead>\n<tr>\n<th>What you see<\/th>\n<th>Cause<\/th>\n<th>Fix<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>TargetFramework doesn&#8217;t support timeout on tests<\/td>\n<td>The old Timeout attribute on modern .NET<\/td>\n<td>Use CancelAfter and pass the test&#8217;s token<\/td>\n<\/tr>\n<tr>\n<td>Skipped, with a reason that CapSkip is not listening<\/td>\n<td>Nothing listens on the host and port<\/td>\n<td>Start CapSkip, check the connection settings, or set CAPSKIP_REQUIRED to fail the run<\/td>\n<\/tr>\n<tr>\n<td>CS0104 on TimeoutException<\/td>\n<td>System and CapSkip both define it<\/td>\n<td>Write CapSkip.TimeoutException, or catch CapSkipError<\/td>\n<\/tr>\n<tr>\n<td>ApiException with ERROR_CAPTCHA_UNSOLVABLE<\/td>\n<td>CapSkip could not solve the CAPTCHA (the default text; the API docs say Settings can replace it)<\/td>\n<td>List the exception in RetryExceptions<\/td>\n<\/tr>\n<tr>\n<td>The site says the token was already used<\/td>\n<td>One token was posted twice, for instance after a retry<\/td>\n<td>Solve inside the test method<\/td>\n<\/tr>\n<tr>\n<td>CS0246 on the NUnit namespace in a net6.0 project<\/td>\n<td>NUnit 5 has no net6.0 build<\/td>\n<td>Target net8.0 or later<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>Other error codes that a solve can raise are listed in the <a href=\"https:\/\/capskip.com\/api-docs\/\">CapSkip API docs<\/a>.<\/p>\n<h2 style=\"font-size:1.6rem;line-height:1.35;\">FAQ<\/h2>\n<details style=\"border:1px solid #e2e5ee;border-radius:10px;padding:14px 18px;margin:0 0 12px;\">\n<summary style=\"cursor:pointer;\">\n<h3 style=\"font-size:1.15rem;line-height:1.4;display:inline;margin:0;\">Does this work with NUnit 4?<\/h3>\n<\/summary>\n<p style=\"margin:12px 0 0;\">Yes. I repeated every run above on NUnit 4.6.1 with the same adapter on net10.0 and got the same results, including the Timeout attribute failing at once; only the net6.0 check concerns 5.0.0 alone. The NUnit docs say RetryExceptions arrived in 4.5.0.<\/p>\n<\/details>\n<details style=\"border:1px solid #e2e5ee;border-radius:10px;padding:14px 18px;margin:0 0 12px;\">\n<summary style=\"cursor:pointer;\">\n<h3 style=\"font-size:1.15rem;line-height:1.4;display:inline;margin:0;\">Can the tests use CapSkip on another machine or a CI agent?<\/h3>\n<\/summary>\n<p style=\"margin:12px 0 0;\">Yes, through Server mode. Put CapSkip in Server mode under connection settings, set CAPSKIP_HOST, CAPSKIP_PORT and STAGING_URL, and the same tests run unchanged. In my run the mock listened on all interfaces and CAPSKIP_HOST was one of this PC&#8217;s own addresses, 192.168.93.1, and the three tests passed; I used no second machine or hosted agent. On a hosted agent 127.0.0.1 is the agent itself, so run CapSkip on a Windows machine you control that the agent can reach, and keep the API key in the CI system&#8217;s secrets.<\/p>\n<p style=\"margin:12px 0 0;\">Between the SDK and CapSkip there is only plain HTTP, so the API key crosses the network readable. Use a private network or VPN and switch API key validation on. Starting Server mode also opens CapSkip to connections from any address, so to limit it, create a Windows Firewall block rule for the others; a narrower allow rule would not close anything.<\/p>\n<\/details>\n<details style=\"border:1px solid #e2e5ee;border-radius:10px;padding:14px 18px;margin:0 0 12px;\">\n<summary style=\"cursor:pointer;\">\n<h3 style=\"font-size:1.15rem;line-height:1.4;display:inline;margin:0;\">Is this the same as the xUnit setup?<\/h3>\n<\/summary>\n<p style=\"margin:12px 0 0;\">The CapSkip calls do not change between the two, but the framework does: xUnit shares a client through a fixture, and NUnit uses a SetUpFixture. I did not run MSTest.<\/p>\n<\/details>\n<h2 style=\"font-size:1.6rem;line-height:1.35;\">The short version<\/h2>\n<p>Build the client once in a SetUpFixture and solve inside every test method. Pass the token from the test context so CancelAfter reaches the solve, keep the SDK timeout as the second limit, and skip Timeout, which is dead on current .NET. Add LevelOfParallelism for parallel runs, keep solves out of OneTimeSetUp and TestCaseSource, and remember that Retry reruns the whole method. For the other CAPTCHA types the .NET package solves, see the <a href=\"https:\/\/capskip.com\/csharp-captcha-solver\/\">C# CAPTCHA solver page<\/a>.<\/p>\n<p>Suites that call a solver hundreds of times a night are where a per-solve price hurts. An <a href=\"https:\/\/capskip.com\/\">unlimited captcha solver<\/a> that runs on your own Windows machine keeps that bill at zero.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>NUnit \u5728\u73b0\u4ee3 .NET \u4e0a\u6ca1\u6709\u53ef\u7528\u7684 Timeout\uff0c\u4e00\u6b21\u53ea\u8fd0\u884c\u4e00\u4e2a\u6d4b\u8bd5\uff0c\u5e76\u4e14\u91cd\u8bd5\u6574\u4e2a\u6d4b\u8bd5\u3002\u8fd9\u91cc\u662f\u4e00\u4e2a\u7528 CapSkip \u8bc6\u522b reCAPTCHA \u7684 C# NUnit \u65b9\u6848\uff0c\u5b83\u9650\u5236\u5e76\u884c\u8bc6\u522b\u7684\u6570\u91cf\uff0c\u5e76\u53d6\u6d88\u5361\u4f4f\u7684\u8bc6\u522b\u3002<\/p>","protected":false},"author":1,"featured_media":28581,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"rank_math_title":"NUnit CAPTCHA Tests in C#: Timeouts and Retries | CapSkip","rank_math_description":"Run an nunit captcha test in C# with CapSkip: one client for the run, a CancelAfter that stops the solve, a worker cap and a safe retry. Copy the code.","rank_math_focus_keyword":"nunit captcha","footnotes":""},"categories":[70],"tags":[],"class_list":["post-28582","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-captcha"],"_links":{"self":[{"href":"https:\/\/capskip.com\/zh\/wp-json\/wp\/v2\/posts\/28582","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/capskip.com\/zh\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/capskip.com\/zh\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/capskip.com\/zh\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/capskip.com\/zh\/wp-json\/wp\/v2\/comments?post=28582"}],"version-history":[{"count":1,"href":"https:\/\/capskip.com\/zh\/wp-json\/wp\/v2\/posts\/28582\/revisions"}],"predecessor-version":[{"id":28583,"href":"https:\/\/capskip.com\/zh\/wp-json\/wp\/v2\/posts\/28582\/revisions\/28583"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/capskip.com\/zh\/wp-json\/wp\/v2\/media\/28581"}],"wp:attachment":[{"href":"https:\/\/capskip.com\/zh\/wp-json\/wp\/v2\/media?parent=28582"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/capskip.com\/zh\/wp-json\/wp\/v2\/categories?post=28582"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/capskip.com\/zh\/wp-json\/wp\/v2\/tags?post=28582"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}