???????

????1. ???JUnit4.x????á?

????2. ???Mock??????????????е???á?

????3. ???Hadoop??MapReduce????????

???????????Junit??Mock??????????????Unit testing with JUnit 4.x and EasyMock in Eclipse - Tutorial ??

???????????Hadoop??MapReduce????????????????????Map/Reduce Tutorial ??

????????

????MRUnit???????Couldera???????????????Hadoop?б?дMapReduce???????????

??????????????0.18.x?汾?е????org.apache.hadoop.mapred.*???????????0.20.x?汾org.apache.hadoop.mapreduce.*???????????á?

???????????????£?

????MRUnit is a unit test library designed to facilitate easy integration between your MapReduce development process and standard development and testing tools such as JUnit. MRUnit contains mock objects that behave like classes you interact with during MapReduce execution (e.g.?? InputSplit and OutputCollector) as well as test harness "drivers" that test your program's correctness while maintaining compliance with the MapReduce semantics. Mapper and Reducer implementations can be tested individually?? as well as together to form a full MapReduce job.

???????

????????Hadoop????а??У????????????MRUnit????????Couldera??????????????????????????η??е?汾??

?????????汾???hadoop-0.20.1+133.tar.gz ??

????????????????????hadoop-0.20.1+133/contrib/mrunit????????????????jar????hadoop-0.20.1+133-mrunit.jar??

??????????MRUnit???????????hadoop-0.20.1+133-mrunit.jar??Junit4.x????jar????junit.jar?????????????Hadoop?????????classpath?С?

???????

???????????????????????????????map???????????????????£?

package gpcuster.cnblogs.com;
import junit.framework.TestCase;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapred.Mapper;
import org.apache.hadoop.mapred.lib.IdentityMapper;
import org.junit.Before;
import org.junit.Test;
import org.apache.hadoop.mrunit.MapDriver;
public class TestExample extends TestCase {
  private Mapper<Text?? Text?? Text?? Text> mapper;
  private MapDriver<Text?? Text?? Text?? Text> driver;
  @Before
  public void setUp() {
    mapper = new IdentityMapper<Text?? Text>();
    driver = new MapDriver<Text?? Text?? Text?? Text>(mapper);
  }
  @Test
  public void testIdentityMapper() {
    driver.withInput(new Text("foo")?? new Text("bar"))
            .withOutput(new Text("foo")?? new Text("bar"))
            .runTest();
  }
}