实践篇(2)--自动化集成学习
下面我举个例子来教大家在实际项目中开展自动化集成(本人也在学习中,还有一些问题):
1) 下载Nant0.85,在环境变量Path中增加Nant\bin的实际目录。
2) 写一个类及其测试类,放到src目录下
using System;
![](/Images/OutliningIndicators/None.gif)
namespace Auto
{
![](/Images/OutliningIndicators/InBlock.gif)
public class Account {
private string _name;
private int _balance;
public Account(string name,int bal)
{
_name=name;
_balance=bal;
![](/Images/OutliningIndicators/InBlock.gif)
}
public void draw(int m)
{
if(m>_balance) throw new Exception("not money!");
_balance-=m;
}
public int Balance
{
get {return _balance;}
![](/Images/OutliningIndicators/InBlock.gif)
}
}
}
using System;
using NUnit.Framework;
namespace Auto
{
[TestFixture]
public class AccountTest {
private Account acc;
[SetUp]
public void Init() {
acc=new Account("lsj",100);
}
[TearDown]
public void Finish() {
}
[Test] public void OKTest() {
![](/Images/OutliningIndicators/InBlock.gif)
acc.draw(50);
Assert.AreEqual(50,acc.Balance);
}
![](/Images/OutliningIndicators/InBlock.gif)
[Test] public void ErrorTest() {
![](/Images/OutliningIndicators/InBlock.gif)
acc.draw(150);
Assert.AreEqual(100,acc.Balance);
}
}
}
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
自动化编译和测试,建立default.build:
<?xml version="1.0"?>
<project name="NUnit Integration" default="test">
<property name="src_dir" value="src" />
<property name="basename" value="account"/>
<property name="debug" value="false"/>
![](/Images/OutliningIndicators/None.gif)
<target name="clean" >
<delete>
<fileset>
<include name="bin/*.dll"/>
</fileset>
</delete>
</target>
![](/Images/OutliningIndicators/None.gif)
<target name="buildPrd" depends="clean" >
<mkdir dir="bin" />
<csc target="library" output="bin/${basename}.dll" debug="${debug}">
<sources>
<include name="${src_dir}/${basename}.cs" />
</sources>
</csc>
</target>
![](/Images/OutliningIndicators/None.gif)
<target name="test" depends="buildPrd">
<csc target="library" output="bin/${basename}-test.dll" debug="${debug}">
<sources>
<include name="${src_dir}/${basename}-test.cs" />
</sources>
<references>
<include name="bin/${basename}.dll" />
<include name="C:\Program Files\NUnit 2.2\bin\nunit.framework.dll" />
</references>
</csc>
<zip zipfile="backup.zip">
<fileset basedir="${src_dir}" prefix="src">
<include name="**/*" />
</fileset>
</zip>
<nunit2>
<formatter type="Plain" />
<test assemblyname="bin/${basename}-test.dll" />
</nunit2>
![](/Images/OutliningIndicators/None.gif)
</target>
![](/Images/OutliningIndicators/None.gif)
<!--
![](/Images/OutliningIndicators/None.gif)
<zip zipfile="backup.zip">
<fileset basedir="${bin.dir}" prefix="bin">
<include name="**/*" />
</fileset>
<fileset basedir="${doc.dir}" prefix="doc">
<include name="**/*" />
</fileset>
</zip>
<mail
from="nant@sourceforge.net"
tolist="recipient1@sourceforge.net"
cclist="recipient2@sourceforge.net"
bcclist="recipient3@sourceforge.net"
subject="Msg 7: With attachments"
mailhost="smtpserver.anywhere.com">
<files>
<include name="*.txt" />
</files>
<attachments>
<include name="*.zip" />
</attachments>
</mail>
<cvs-checkout
destination="c:\src\nant"
cvsroot=":pserver:anonymous@cvs.sourceforge.net:/cvsroot/nant"
password=""
module="nant"
revision="0_85"
overridedir="v0.85">
</cvs-checkout>
![](/Images/OutliningIndicators/None.gif)
-->
</project>注意要修改C:\Program Files\NUnit 2.2\bin\nunit.framework.dll成你自己的实际引用
运行结果:除了单元测试的没有显示外,其他都可以,包括最后的打包工作。
我注解掉的自动CVS操作和邮件发送,才具有真正的价值,留给读者去练习吧。
下载练习包:
执行:在DOS窗口下进入练习目录,打入nant .
好了,可以去喝茶轻松一下,回来可以看到结果。
alex
1) 下载Nant0.85,在环境变量Path中增加Nant\bin的实际目录。
2) 写一个类及其测试类,放到src目录下
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/ExpandedBlockStart.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
![](/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
![](/Images/OutliningIndicators/ExpandedBlockEnd.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/ExpandedBlockStart.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
![](/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
![](/Images/OutliningIndicators/ExpandedBlockEnd.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
自动化编译和测试,建立default.build:
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
运行结果:除了单元测试的没有显示外,其他都可以,包括最后的打包工作。
我注解掉的自动CVS操作和邮件发送,才具有真正的价值,留给读者去练习吧。
下载练习包:
执行:在DOS窗口下进入练习目录,打入nant .
好了,可以去喝茶轻松一下,回来可以看到结果。
alex