Hadoop 0.21如何运行单个test case

Linux大全评论335 views阅读模式

研究Hadoop 0.21代码时,很多情况下需要运行单个test case,如果新增了功能要测试case能否通过或者自己写的test case需要测试等。而把test case全部运行一遍是很耗时的,严重影响开发效率。这里提供一个0.21 mapreduce的一个diff文件,用以修改build.xml文件,打上patch后即可在本地运行单个test case了。

  1. Index: build.xml  
  2. ===================================================================  
  3. --- build.xml   (revision 1102542)  
  4. +++ build.xml   (working copy)  
  5. @@ -685,6 +685,7 @@  
  6.                       value="@{hadoop.conf.dir.deployed}" />  
  7.          <classpath refid="@{classpath}"/>  
  8.          <formatter type="${test.junit.output.format}" />  
  9. +        <test name="${testcase}" todir="${test.build.dir}" if="testcase"/>  
  10.          <batchtest todir="@{test.dir}" unless="testcase">  
  11.            <fileset dir="@{fileset.dir}/@{suite.type}"  
  12.              excludes="**/${test.exclude}.java aop/** system/**">  
  13. @@ -776,7 +777,18 @@  
  14.        fileset.dir="${test.src.dir}"/>  
  15.     </target>  
  16.    
  17. +  <target name="run-ut"  
  18. +    depends="compile-mapred-test" if="testcase">  
  19. +    <macro-test-runner  
  20. +      test.file="${test.mapred.all.tests.file}"  
  21. +      suite.type="mapred"  
  22. +      classpath="${test.classpath.id}"  
  23. +      test.dir="${test.build.dir}"  
  24. +      fileset.dir="${test.src.dir}"/>  
  25. +  </target>  
  26.    
  27. +  
  28. +  
  29.    <target name="checkfailure" if="tests.failed">  
  30.      <touch file="${test.build.dir}/testsfailed"/>  
  31.      <fail unless="continueOnFailure">Tests failed!</fail>  

示例如下:

ant run-ut -Dtestcase="org.apache.hadoop.conf.TestJobConf"

运行结束后就可以在${test.build.dir},即build/test看到log文件了。如上面的示例的log文件为:

企鹅博客
  • 本文由 发表于 2020年9月24日 01:15:04
  • 转载请务必保留本文链接:https://www.qieseo.com/149414.html

发表评论