研究Hadoop 0.21代码时,很多情况下需要运行单个test case,如果新增了功能要测试case能否通过或者自己写的test case需要测试等。而把test case全部运行一遍是很耗时的,严重影响开发效率。这里提供一个0.21 mapreduce的一个diff文件,用以修改build.xml文件,打上patch后即可在本地运行单个test case了。
Index: build.xml =================================================================== --- build.xml (revision 1102542) +++ build.xml (working copy) @@ -685,6 +685,7 @@ value="@{hadoop.conf.dir.deployed}" /> <classpath refid="@{classpath}"/> <formatter type="${test.junit.output.format}" /> + <test name="${testcase}" todir="${test.build.dir}" if="testcase"/> <batchtest todir="@{test.dir}" unless="testcase"> <fileset dir="@{fileset.dir}/@{suite.type}" excludes="**/${test.exclude}.java aop/** system/**"> @@ -776,7 +777,18 @@ fileset.dir="${test.src.dir}"/> </target> + <target name="run-ut" + depends="compile-mapred-test" if="testcase"> + <macro-test-runner + test.file="${test.mapred.all.tests.file}" + suite.type="mapred" + classpath="${test.classpath.id}" + test.dir="${test.build.dir}" + fileset.dir="${test.src.dir}"/> + </target> + + <target name="checkfailure" if="tests.failed"> <touch file="${test.build.dir}/testsfailed"/> <fail unless="continueOnFailure">Tests failed!</fail>示例如下:
ant run-ut -Dtestcase="org.apache.hadoop.conf.TestJobConf"
运行结束后就可以在${test.build.dir},即build/test看到log文件了。如上面的示例的log文件为:
build/test/TEST-org.apache.hadoop.conf.TestJobConf.txt