Teamcity 通过添加 DataOnStack 结构来修改我自己的程序集
为了确保编码标准,我有几个单元测试,它使用反射来查看没有任何问题。其中之一如下所示:
[Test]
public void All_structs_should_be_immutable()
{
var mutableStructs = typeof (Product).Assembly
.GetTypes()
.Where(type =>
type.IsValueType && !type.IsCompilerGenerated() &&
!type.GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic).All(
field => field.IsInitOnly))
.OrderBy(type => type.FullName);
foreach (var mutableStruct in mutableStructs)
{
Console.WriteLine(mutableStruct.FullName);
}
Assert.AreEqual("", string.Join(", ", mutableStructs.Select(x => x.FullName).ToArray()));
Assert.AreEqual(0, mutableStructs.Count());
}
Product 类位于我自己的程序集中,与 Jetbrains/Teamcity 无关。
使用 Resharper 运行测试时效果很好。但是当我在 Teamcity 中运行它时,出现以下错误:
测试失败。预期字符串长度为 0,但实际长度为 51。字符串在索引 0 处不同。
预期:
但是是:“JetBrains.Profiler.Core.Instrumentation.DataOnStack”
------------^
at NUnit.Framework.Assert.That(实际对象,IResolveConstraint 表达式,字符串消息,Object[] args)
at NUnit.Framework.Assert.AreEqual(预期对象,实际对象)
位于 c:\TeamCity\buildAgent\work\99395abb82d2a3b3\Test\Litium.Kamakura.UnitTest\CodingStandards\ImmutableStructs.cs 中的 Litium.Kamakura.UnitTest.CodingStandards.ImmutableStructs.All_structs_should_be_immutable():第 26 行
-------- 标准输出:--------
JetBrains.Profiler.Core.Instrumentation.DataOnStack
Teamcity 如何以及为何修改我的程序集?
To ensure coding standards I have a couple of unit test which uses reflection to see that nothing is wrong. One of those looks like this:
[Test]
public void All_structs_should_be_immutable()
{
var mutableStructs = typeof (Product).Assembly
.GetTypes()
.Where(type =>
type.IsValueType && !type.IsCompilerGenerated() &&
!type.GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic).All(
field => field.IsInitOnly))
.OrderBy(type => type.FullName);
foreach (var mutableStruct in mutableStructs)
{
Console.WriteLine(mutableStruct.FullName);
}
Assert.AreEqual("", string.Join(", ", mutableStructs.Select(x => x.FullName).ToArray()));
Assert.AreEqual(0, mutableStructs.Count());
}
The Product class is within my own assembly which has nothing to do with Jetbrains/Teamcity.
This works fine when running the tests with Resharper. But when I run it in Teamcity, I get this error:
Test(s) failed. Expected string length 0 but was 51. Strings differ at index 0.
Expected:
But was: "JetBrains.Profiler.Core.Instrumentation.DataOnStack"
-----------^
at NUnit.Framework.Assert.That(Object actual, IResolveConstraint expression, String message, Object[] args)
at NUnit.Framework.Assert.AreEqual(Object expected, Object actual)
at Litium.Kamakura.UnitTest.CodingStandards.ImmutableStructs.All_structs_should_be_immutable() in c:\TeamCity\buildAgent\work\99395abb82d2a3b3\Test\Litium.Kamakura.UnitTest\CodingStandards\ImmutableStructs.cs:line 26
------- Stdout: -------
JetBrains.Profiler.Core.Instrumentation.DataOnStack
How and why does Teamcity modify my assembly?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
看起来 Teamcity 的测试运行程序(NUnit 测试运行程序?)被配置为使用 dotCover / dotTrace 运行。上面的分析器之一已经编辑了您的代码(请记住,它们是 .net 分析器,并且它们可以在 JIT 编译时注入代码等)。
根据这个 bug track,Jetbrains 使用此结构并且不会删除它,因此您将不得不使用解决方法。
另请参阅 Teamcity 文档 - 您可以尝试使用不同的运行器运行,或使用 NCover 收集覆盖范围,或完全禁用覆盖范围。
It seems as Teamcity's test runner (NUnit test runner?) was configured to run with dotCover / dotTrace. One of the profilers above has edited your code (remember that they are .net profilers, and they can inject code at JIT compile time, among others).
According to this bug track, Jetbrains use this structure and will not remove it, so you will have to use a workaround.
See also Teamcity documentation - you can try running with a different runner, or collecting coverage with NCover, or disable coverage altogether.