You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@mrunit.apache.org by Thamizhannal <an...@gmail.com> on 2012/10/18 16:58:11 UTC

MRUnit TestCase on JunitTest suite issue

Hi All,
I am trying to run a MRUnit test case using test suite. TestCase works
well when I ran it seperately. It throws null pointer error when I
configure it on TestSuite. It does not pick variable (line1 Or
Configuration ) values on Test Suite(AllTest.java). Why is this? What
is wrong on below code.

I have couple of Hadoop-0.19 & hadoop-0.20 test cases and below Jars I am using
mrunit-0.9.0-incubating-hadoop1.jar
mockito-all-1.8.5.jar
junit-4.10.jar

Any help would be appreciated.

public class LogParseMRUnitTest extends TestCase{
	MapReduceDriver<LongWritable, Text, Text, Log, Text, Log> mapReduceDriver;
	MapDriver<LongWritable, Text, Text, Log> mapDriver;
	ReduceDriver<Text, Log, Text, Log> reduceDriver;
	String line1 = "text here";	
	
	@Before
	public void setup() {
		LogParseMapper mapper = new LogParseMapper();
		mapDriver = new MapDriver<LongWritable, Text, Text, Log>();
		mapDriver.setMapper(mapper);
		Configuration conf = new Configuration();
		conf.set("dbfile","dbfile location");
		mapDriver.setConfiguration(conf);
	}

	@Test
	public void testMapper() throws IOException {
		mapDriver.withInput(new LongWritable(), new Text(line1));
		Log log = log.populateData(line1.toLowerCase());
		String key = log.getKey()
		mapDriver.withOutput(new Text(key), log);
	}
}

public final class AllTests {
	public static Test suite() {
		TestSuite suite = new TestSuite("Test for org.apache.hadoop.mrunit");
		suite.addTestSuite(LogParseMRUnitTest.class);
		return suite;
	}
}

Thanks,
Tamil

Re: MRUnit TestCase on JunitTest suite issue

Posted by Brock Noland <br...@cloudera.com>.
Hi,

Hopefully someone will be able to help you, but I just had a quick
question. Do you use maven?

Brock

On Thu, Oct 18, 2012 at 9:58 AM, Thamizhannal <an...@gmail.com> wrote:
> Hi All,
> I am trying to run a MRUnit test case using test suite. TestCase works
> well when I ran it seperately. It throws null pointer error when I
> configure it on TestSuite. It does not pick variable (line1 Or
> Configuration ) values on Test Suite(AllTest.java). Why is this? What
> is wrong on below code.
>
> I have couple of Hadoop-0.19 & hadoop-0.20 test cases and below Jars I am using
> mrunit-0.9.0-incubating-hadoop1.jar
> mockito-all-1.8.5.jar
> junit-4.10.jar
>
> Any help would be appreciated.
>
> public class LogParseMRUnitTest extends TestCase{
>         MapReduceDriver<LongWritable, Text, Text, Log, Text, Log> mapReduceDriver;
>         MapDriver<LongWritable, Text, Text, Log> mapDriver;
>         ReduceDriver<Text, Log, Text, Log> reduceDriver;
>         String line1 = "text here";
>
>         @Before
>         public void setup() {
>                 LogParseMapper mapper = new LogParseMapper();
>                 mapDriver = new MapDriver<LongWritable, Text, Text, Log>();
>                 mapDriver.setMapper(mapper);
>                 Configuration conf = new Configuration();
>                 conf.set("dbfile","dbfile location");
>                 mapDriver.setConfiguration(conf);
>         }
>
>         @Test
>         public void testMapper() throws IOException {
>                 mapDriver.withInput(new LongWritable(), new Text(line1));
>                 Log log = log.populateData(line1.toLowerCase());
>                 String key = log.getKey()
>                 mapDriver.withOutput(new Text(key), log);
>         }
> }
>
> public final class AllTests {
>         public static Test suite() {
>                 TestSuite suite = new TestSuite("Test for org.apache.hadoop.mrunit");
>                 suite.addTestSuite(LogParseMRUnitTest.class);
>                 return suite;
>         }
> }
>
> Thanks,
> Tamil



-- 
Apache MRUnit - Unit testing MapReduce - http://incubator.apache.org/mrunit/

Re: MRUnit TestCase on JunitTest suite issue

Posted by Thamizhannal <an...@gmail.com>.
Thanks a lot for your inputs.
I did not use maven.
Since, I combined junit4 & junit3 convention  which created trouble to me.
Now, I sticked to Junit4 conversion now.
I used JUnitCore.runClasses(testSuites) to fire my test cases those were
written using MRUnit.
Thanks a lot for your help.

Thanks,
Tamil

On Thu, Oct 18, 2012 at 8:37 PM, Bertrand Dechoux <de...@gmail.com>wrote:

> Hi Tamil,
>
> Could you provide the stack trace?
>
> Mixing TestCase and annotations is weird. I am not an expert in the former
> so there might be use cases but the former is usually for junit 3 (without
> annotations) and the latter for junit 4 (with annotations).
>
> Your problem is probably with the use of junit itself and not MRUnit.
>
> Could check that in both case your setup is called?
>
> Regards
>
> Bertrand
>
>
> On Thu, Oct 18, 2012 at 4:58 PM, Thamizhannal <an...@gmail.com> wrote:
>
>> Hi All,
>> I am trying to run a MRUnit test case using test suite. TestCase works
>> well when I ran it seperately. It throws null pointer error when I
>> configure it on TestSuite. It does not pick variable (line1 Or
>> Configuration ) values on Test Suite(AllTest.java). Why is this? What
>> is wrong on below code.
>>
>> I have couple of Hadoop-0.19 & hadoop-0.20 test cases and below Jars I am
>> using
>> mrunit-0.9.0-incubating-hadoop1.jar
>> mockito-all-1.8.5.jar
>> junit-4.10.jar
>>
>> Any help would be appreciated.
>>
>> public class LogParseMRUnitTest extends TestCase{
>>         MapReduceDriver<LongWritable, Text, Text, Log, Text, Log>
>> mapReduceDriver;
>>         MapDriver<LongWritable, Text, Text, Log> mapDriver;
>>         ReduceDriver<Text, Log, Text, Log> reduceDriver;
>>         String line1 = "text here";
>>
>>         @Before
>>         public void setup() {
>>                 LogParseMapper mapper = new LogParseMapper();
>>                 mapDriver = new MapDriver<LongWritable, Text, Text,
>> Log>();
>>                 mapDriver.setMapper(mapper);
>>                 Configuration conf = new Configuration();
>>                 conf.set("dbfile","dbfile location");
>>                 mapDriver.setConfiguration(conf);
>>         }
>>
>>         @Test
>>         public void testMapper() throws IOException {
>>                 mapDriver.withInput(new LongWritable(), new Text(line1));
>>                 Log log = log.populateData(line1.toLowerCase());
>>                 String key = log.getKey()
>>                 mapDriver.withOutput(new Text(key), log);
>>         }
>> }
>>
>> public final class AllTests {
>>         public static Test suite() {
>>                 TestSuite suite = new TestSuite("Test for
>> org.apache.hadoop.mrunit");
>>                 suite.addTestSuite(LogParseMRUnitTest.class);
>>                 return suite;
>>         }
>> }
>>
>> Thanks,
>> Tamil
>>
>
>
>
> --
> Bertrand Dechoux
>



-- 
Regards,
Thamizhannal

Re: MRUnit TestCase on JunitTest suite issue

Posted by Bertrand Dechoux <de...@gmail.com>.
Hi Tamil,

Could you provide the stack trace?

Mixing TestCase and annotations is weird. I am not an expert in the former
so there might be use cases but the former is usually for junit 3 (without
annotations) and the latter for junit 4 (with annotations).

Your problem is probably with the use of junit itself and not MRUnit.

Could check that in both case your setup is called?

Regards

Bertrand

On Thu, Oct 18, 2012 at 4:58 PM, Thamizhannal <an...@gmail.com> wrote:

> Hi All,
> I am trying to run a MRUnit test case using test suite. TestCase works
> well when I ran it seperately. It throws null pointer error when I
> configure it on TestSuite. It does not pick variable (line1 Or
> Configuration ) values on Test Suite(AllTest.java). Why is this? What
> is wrong on below code.
>
> I have couple of Hadoop-0.19 & hadoop-0.20 test cases and below Jars I am
> using
> mrunit-0.9.0-incubating-hadoop1.jar
> mockito-all-1.8.5.jar
> junit-4.10.jar
>
> Any help would be appreciated.
>
> public class LogParseMRUnitTest extends TestCase{
>         MapReduceDriver<LongWritable, Text, Text, Log, Text, Log>
> mapReduceDriver;
>         MapDriver<LongWritable, Text, Text, Log> mapDriver;
>         ReduceDriver<Text, Log, Text, Log> reduceDriver;
>         String line1 = "text here";
>
>         @Before
>         public void setup() {
>                 LogParseMapper mapper = new LogParseMapper();
>                 mapDriver = new MapDriver<LongWritable, Text, Text, Log>();
>                 mapDriver.setMapper(mapper);
>                 Configuration conf = new Configuration();
>                 conf.set("dbfile","dbfile location");
>                 mapDriver.setConfiguration(conf);
>         }
>
>         @Test
>         public void testMapper() throws IOException {
>                 mapDriver.withInput(new LongWritable(), new Text(line1));
>                 Log log = log.populateData(line1.toLowerCase());
>                 String key = log.getKey()
>                 mapDriver.withOutput(new Text(key), log);
>         }
> }
>
> public final class AllTests {
>         public static Test suite() {
>                 TestSuite suite = new TestSuite("Test for
> org.apache.hadoop.mrunit");
>                 suite.addTestSuite(LogParseMRUnitTest.class);
>                 return suite;
>         }
> }
>
> Thanks,
> Tamil
>



-- 
Bertrand Dechoux