简体   繁体   English

从gulp nunit运行结果中隐藏SamlMessageSignature输出

[英]Hide SamlMessageSignature output from gulp nunit run results

When using gulp-nunit-runner to run NUnit tests for SAMLMessageSignature message that is being signed is shown in console output. 当使用gulp-nunit-runner运行NUnit测试以对正在签名的SAMLMessageSignature消息进行显示时,将显示在控制台输出中。 Options like noresult = true, verbose = false, trace = 'Off' have no effect. noresult = true, verbose = false, trace = 'Off'等选项无效。 I can redirect the output to a file but I'd prefer to not do it. 我可以将输出重定向到文件,但我不想这样做。 When using nunit3-console.exe with --trace=Off --noresult options there is no output, just Test Run Summary. 当将nunit3-console.exe--trace=Off --noresult选项一起使用时,没有输出,只有“测试运行摘要”。

Is there a way to prevent SAMLMessage from being printed to console output without redirecting whole output to a file? 有没有一种方法可以防止在不将整个输出重定向到文件的情况下将SAMLMessage打印到控制台输出?

Example test: 测试示例:

[Test]
public void SamlMessageSignatureGenerate_SamlDocumentAndValidCert_ProducesSignedSamlMessage(
    [ValueSource(nameof(MessagesToSign))] string samlMessage,
    [ValueSource(nameof(Certs))] X509Certificate2 cert,
    [ValueSource(nameof(SupportedSignatureMethods))] string signatureMethod,
    [ValueSource(nameof(SupportedDigestMethods))] string digestMethod)
{
    XmlElement samlDoc = SamlLoader.LoadXmlFromString(samlMessage).DocumentElement;
    string inclusiveNamespacesPrefixList = null;
    SAMLMessageSignature.Generate(samlDoc, cert.PrivateKey, cert, inclusiveNamespacesPrefixList, digestMethod, signatureMethod);
    SAMLMessageSignature.IsSigned(samlDoc).Should().BeTrue();
}

For some reason samlMessage ends up in console output. 由于某种原因, samlMessage最终出现在控制台输出中。

The options --result , --noresult , --trace have nothing whatsoever to do with console output but serve other purposes. 选项--result--noresult--trace都毫无关系与控制台输出,但用于其他目的。

The option --verbose can be used to provide additional details for some (only some) messages generated by NUnit . 选项--verbose可用于为NUnit生成的某些(仅某些)消息提供更多详细信息。

Console output can be redirected to a file using the --out option, which impacts all output sent to the console by a test. 可以使用--out选项将控制台输出重定向到文件,这会影响测试发送到控制台的所有输出。 Most likely, your SAML output appears to NUnit as if it is generated by a test. 您的SAML输出很可能在NUnit中显示,就像它是由测试生成的一样。

In this case, where you wish to suppress the output generated by a particular test, there are two options: 在这种情况下,如果您希望抑制特定测试生成的输出,则有两种选择:

  1. Use some settings, if they exist, so that the output is never generated. 使用某些设置(如果存在),以使永远不会生成输出。 I don't know if this is possible in your case. 我不知道您是否可以这样做。

  2. Redirect the console output for your test, capturing it yourself and then restore it at the end of the test. 重定向测试的控制台输出,自己捕获它,然后在测试结束时将其还原。

If you want to do (2) then you have to remember that the console is shared by the entire process. 如果要执行(2),则必须记住控制台是整个过程共享的。 Therefore, your test must never run in parallel with other tests. 因此,您的测试绝不能与其他测试并行运行。 If you are running some tests in parallel, then mark that one as [NonParallelizable] . 如果要并行运行某些测试,则将该测试标记为[NonParallelizable]

To redirect the console, create a StringWriter and set Console.Out to it for the duration of the test. 要重定向控制台,请创建一个StringWriter并在测试期间将Console.Out设置为该控制台。 If you wish, you can examine what is written as a part of your test. 如果您愿意,可以检查在测试中编写的内容。

If all the tests in a particular fixture require suppressing console output, then you can do it in either a [SetUp] or a [OneTimeSetUp] method. 如果特定固定装置中的所有测试都需要抑制控制台输出,则可以使用[SetUp][OneTimeSetUp]方法进行。 Otherwise, do it in each individual test, possibly through a using statement. 否则,可以在每个单独的测试中执行此操作,可能需要通过using语句。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM