今天想在自动集成服务器上用MSTest,但遗憾的是MSTest.exe不能使用目录,命名空间等,因此需要将MSTest转换为Nunit1.
1. 首先移除MSTest的程序集,引入Nunit.Framework.dll
2.然后使用如下Ruby脚本.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
|
all_files=
Dir
[
File
.join(
"D:"
,
"UnitTest/**/**/**"
)];
all_files.
each
{ |x|
if
x.to_s().include?(
".cs"
)
begin
puts x.to_s
f =
File
.open(x.to_s,
"r+"
)
content=
""
f.
each
{ |line| content+=line }
s=content.gsub(/\[TestMethod\]/,
"[Test]"
).gsub(/\[TestMethod\(\)\]/,
"[Test]"
).
gsub(/\[TestClass\]/,
"[TestFixture]"
).gsub(/\[TestClass\(\)\]/,
"[TestFixture]"
).
gsub(/\[ClassInitialize\]/,
"[TestFixtureSetUp]"
).gsub(/\[ClassInitialize\(\)\]/,
"[TestFixtureSetUp]"
).
gsub(/\[ClassCleanup\]/,
"[TestFixtureTearDown]"
).gsub(/\[ClassCleanup\(\)\]/,
"[TestFixtureTearDown]"
).
gsub(/\[TestInitialize\]/,
"[SetUp]"
).gsub(/\[TestInitialize\(\)\]/,
"[SetUp]"
).
gsub(/\[TestCleanUp\]/,
"[TearDown]"
).gsub(/\[TestCleanUp\(\)\]/,
"[TearDown]"
).
gsub(/\[AssemblyInitialize\]/,
""
). gsub(/\[AssemblyInitialize\(\)\]/,
""
).
gsub(/\[AssemblyCleanUp\]/,
""
).gsub(/\[AssemblyCleanUp\(\)\]/,
""
).
gsub(/namespace\s+?/,
"using NUnit.Framework;\n\nnamespace "
)
f.close
File
.delete(x)
new
=
File
.
new
(x,
"w+"
)
new
.puts s
new
.close
s=
""
rescue
=>e
end
end
}
|
1
|
3
. 移除MSTest的部分特性的东西,如TestContext等,这个应该很少了
|
1
|
然后,就顺利转换成功了
|
1
|
|
1
|
|
王德水