You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@mrunit.apache.org by Qian Ye <ye...@gmail.com> on 2012/06/20 05:57:53 UTC

Some unittest failed when I use "mvn test", but it can pass when I use "mvn test -Dtest=xxxxx"

Hi all:

I use MRUnit in my project using hadoop/hbase. It works well at first.
These days I came across a strange situation. Some unittest failed when I
use "mvn test", but it can pass when I use "mvn test -Dtest=xxxxx". The
mapreduce program which is tested by the unittest read from hdfs and write
to a hbase table. Has anyone met the same situation? Thanks for any help.

-- 
With Regards!

Ye, Qian

Re: Some unittest failed when I use "mvn test", but it can pass when I use "mvn test -Dtest=xxxxx"

Posted by Dave Beech <db...@apache.org>.
Do your tests involve dates, or other randomly generated values like uuids?
These can often cause unpredictable test outcomes.

On 26 June 2012 08:57, Qian Ye <ye...@gmail.com> wrote:

> The problem still there ... -_-!
> I ran "mvn test" today, and the same assertion failure came out again.
> Anymore advice about it?
>
>
>
> On Sun, Jun 24, 2012 at 1:11 PM, Qian Ye <ye...@gmail.com> wrote:
>
>> Yes Dave, the setUp is only called once. I added cleanupTestDir() before
>> shutdownMiniCluster() in tearDown, and the testcase group passed. However,
>> I still don't understand the reason.
>>
>> On Fri, Jun 22, 2012 at 12:44 AM, Dave Beech <db...@apache.org> wrote:
>>
>>> Or maybe it's something in the /tmp/mr folder not being cleared
>>> properly??
>>>
>>>
>>> On 21 June 2012 17:42, Dave Beech <db...@apache.org> wrote:
>>>
>>>> I don't think setUp would be called twice actually - I don't think
>>>> JUnit would see the @Before annotation on the parent class, so calling
>>>> super.setUp in that way is probably OK.
>>>>
>>>> It might be possible to use @BeforeClass and @AfterClass to start up
>>>> and tear down the mini cluster once, which will no doubt make the tests run
>>>> quicker but I'm not sure that's the issue here.
>>>>
>>>> If tests pass individually but fail as a group, there must be some
>>>> unintended sharing of state *somewhere*.  You have createTable calls in the
>>>> @Before setup method, so should you explicitly delete them again after each
>>>> test? Apologies, I am not too experienced with testing HBase in this way.
>>>>
>>>>
>>>> On 21 June 2012 15:25, Haijia Zhou <ha...@adobe.com> wrote:
>>>>
>>>>> I think your code is sort of messed up, some comments:****
>>>>>
>>>>> **1.       **Why not use @BeforeClass in the base class and make
>>>>> ‘setUp()’ method static since it’s supposed to be one time thing****
>>>>>
>>>>> **2.       **What’s the point of having ‘setUP()’ in both classes and
>>>>> calling parent class’s setUp() from child class’s setUp()****
>>>>>
>>>>> I would think in your case the MiniMRTestBase.setUp() will be called
>>>>> at least twice for each test, that might cause the issue.****
>>>>>
>>>>> ** **
>>>>>
>>>>> *From:* Qian Ye [mailto:yeqian.zju@gmail.com]
>>>>> *Sent:* Wednesday, June 20, 2012 11:54 PM
>>>>> *To:* Dave Beech
>>>>> *Cc:* user@mrunit.apache.org
>>>>> *Subject:* Re: Some unittest failed when I use "mvn test", but it can
>>>>> pass when I use "mvn test -Dtest=xxxxx"****
>>>>>
>>>>> ** **
>>>>>
>>>>> Thanks Dave, here is more details. I have a base class like this:
>>>>>
>>>>> public class MiniMRTestBase {
>>>>>
>>>>>     public final static HBaseTestingUtility util = new
>>>>> HBaseTestingUtility();
>>>>>
>>>>>     @Before
>>>>>     public void setUp() throws Exception {
>>>>>
>>>>>         util.getConfiguration().addResource("hbase-site-local.xml");
>>>>>         util.getConfiguration().reloadConfiguration();
>>>>>
>>>>>         util.getConfiguration().set("mapred.local.dir", "/tmp/mr");
>>>>>
>>>>>         util.startMiniCluster(1);
>>>>>     }
>>>>>
>>>>>     @After
>>>>>     public void tearDown() throws Exception {
>>>>>         util.shutdownMiniCluster();
>>>>>     }
>>>>> }
>>>>>
>>>>> and all the test case extend this class. In the subclass, I use this
>>>>> setup function to create table in testing hbase cluster.
>>>>>     @Before
>>>>>     public void setUp() throws Exception {
>>>>>         super.setUp();
>>>>>         // create table
>>>>>         installHistoryTbl = util.createTable(INSTALL_HISTORY,
>>>>> INSTALL_CF);
>>>>>         dailyLaunchIndexTbl = util.createTable(DAILY_LAUNCH_INDEX,
>>>>> LAUNCH_CF);
>>>>>         deviceInfoTbl = util.createTable(DEVICE_INFO, INFO_CF);
>>>>>         appusercountTbl = util.createTable(APP_USER_COUNT, STAT_CF);
>>>>>     }
>>>>>
>>>>> In my opinion, in this situation, test case in different testing
>>>>> subclass should not affect others, that is when I use "mvn test", the
>>>>> result should be the same as the result of "mvn test -Dtest=xxxxx". But
>>>>> "mvn test" gave me a assertion failure. It is interesting that I have about
>>>>> 80 test cases, and the assertion failure only occur in 1 test case. The
>>>>> stack traces is,
>>>>>
>>>>> testHourlyMapReduceTempSvrTime(com.umeng.dp.mapreduce.HourlyProcedureMapReduceTest)
>>>>> Time elapsed: 24.476 sec  <<< FAILURE!
>>>>> java.lang.AssertionError: expected:<2012-03-20 17:00:28> but was:<null>
>>>>>     at org.junit.Assert.fail(Assert.java:91)
>>>>>     at org.junit.Assert.failNotEquals(Assert.java:645)
>>>>>     at org.junit.Assert.assertEquals(Assert.java:126)
>>>>>     at org.junit.Assert.assertEquals(Assert.java:145)
>>>>>     at
>>>>> com.umeng.dp.mapreduce.HourlyProcedureMapReduceTest.testHourlyMapReduceTempSvrTime(HourlyProcedureMapReduceTest.java:729)
>>>>>     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
>>>>>     at
>>>>> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
>>>>>     at
>>>>> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
>>>>>     at java.lang.reflect.Method.invoke(Method.java:597)
>>>>>     at
>>>>> org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)
>>>>>     at
>>>>> org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
>>>>>     at
>>>>> org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)
>>>>>     at
>>>>> org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
>>>>>     at
>>>>> org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28)
>>>>>     at
>>>>> org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:31)
>>>>>     at
>>>>> org.junit.runners.BlockJUnit4ClassRunner.runNotIgnored(BlockJUnit4ClassRunner.java:79)
>>>>>     at
>>>>> org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:71)
>>>>>     at
>>>>> org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:49)
>>>>>     at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193)
>>>>>     at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52)
>>>>>     at
>>>>> org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191)
>>>>>     at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42)
>>>>>     at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184)
>>>>>     at org.junit.runners.ParentRunner.run(ParentRunner.java:236)
>>>>>     at
>>>>> org.apache.maven.surefire.junit4.JUnit4TestSet.execute(JUnit4TestSet.java:53)
>>>>>     at
>>>>> org.apache.maven.surefire.junit4.JUnit4Provider.executeTestSet(JUnit4Provider.java:123)
>>>>>     at
>>>>> org.apache.maven.surefire.junit4.JUnit4Provider.invoke(JUnit4Provider.java:104)
>>>>>     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
>>>>>     at
>>>>> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
>>>>>     at
>>>>> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
>>>>>     at java.lang.reflect.Method.invoke(Method.java:597)
>>>>>     at
>>>>> org.apache.maven.surefire.util.ReflectionUtils.invokeMethodWithArray(ReflectionUtils.java:164)
>>>>>     at
>>>>> org.apache.maven.surefire.booter.ProviderFactory$ProviderProxy.invoke(ProviderFactory.java:110)
>>>>>     at
>>>>> org.apache.maven.surefire.booter.SurefireStarter.invokeProvider(SurefireStarter.java:175)
>>>>>     at
>>>>> org.apache.maven.surefire.booter.SurefireStarter.runSuitesInProcessWhenForked(SurefireStarter.java:107)
>>>>>     at
>>>>> org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:68)
>>>>> testHourlyMapReduceAccTypeCarrier(com.umeng.dp.mapreduce.HourlyProcedureMapReduceTest)
>>>>> Time elapsed: 24.279 sec  <<< FAILURE!
>>>>> java.lang.AssertionError: expected:<2g/3g> but was:<null>
>>>>>     at org.junit.Assert.fail(Assert.java:91)
>>>>>     at org.junit.Assert.failNotEquals(Assert.java:645)
>>>>>     at org.junit.Assert.assertEquals(Assert.java:126)
>>>>>     at org.junit.Assert.assertEquals(Assert.java:145)
>>>>>     at
>>>>> com.umeng.dp.mapreduce.HourlyProcedureMapReduceTest.testHourlyMapReduceAccTypeCarrier(HourlyProcedureMapReduceTest.java:761)
>>>>>     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
>>>>>     at
>>>>> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
>>>>>     at
>>>>> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
>>>>>     at java.lang.reflect.Method.invoke(Method.java:597)
>>>>>     at
>>>>> org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)
>>>>>     at
>>>>> org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
>>>>>     at
>>>>> org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)
>>>>>     at
>>>>> org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
>>>>>     at
>>>>> org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28)
>>>>>     at
>>>>> org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:31)
>>>>>     at
>>>>> org.junit.runners.BlockJUnit4ClassRunner.runNotIgnored(BlockJUnit4ClassRunner.java:79)
>>>>>     at
>>>>> org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:71)
>>>>>     at
>>>>> org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:49)
>>>>>     at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193)
>>>>>     at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52)
>>>>>     at
>>>>> org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191)
>>>>>     at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42)
>>>>>     at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184)
>>>>>     at org.junit.runners.ParentRunner.run(ParentRunner.java:236)
>>>>>     at
>>>>> org.apache.maven.surefire.junit4.JUnit4TestSet.execute(JUnit4TestSet.java:53)
>>>>>     at
>>>>> org.apache.maven.surefire.junit4.JUnit4Provider.executeTestSet(JUnit4Provider.java:123)
>>>>>     at
>>>>> org.apache.maven.surefire.junit4.JUnit4Provider.invoke(JUnit4Provider.java:104)
>>>>>     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
>>>>>     at
>>>>> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
>>>>>     at
>>>>> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
>>>>>     at java.lang.reflect.Method.invoke(Method.java:597)
>>>>>     at
>>>>> org.apache.maven.surefire.util.ReflectionUtils.invokeMethodWithArray(ReflectionUtils.java:164)
>>>>>     at
>>>>> org.apache.maven.surefire.booter.ProviderFactory$ProviderProxy.invoke(ProviderFactory.java:110)
>>>>>     at
>>>>> org.apache.maven.surefire.booter.SurefireStarter.invokeProvider(SurefireStarter.java:175)
>>>>>     at
>>>>> org.apache.maven.surefire.booter.SurefireStarter.runSuitesInProcessWhenForked(SurefireStarter.java:107)
>>>>>     at
>>>>> org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:68)
>>>>>
>>>>> Thanks for ur help!
>>>>>
>>>>> ****
>>>>>
>>>>> On Wed, Jun 20, 2012 at 4:07 PM, Dave Beech <db...@apache.org> wrote:
>>>>> ****
>>>>>
>>>>> Hi Qian, ****
>>>>>
>>>>> ** **
>>>>>
>>>>> It may be difficult to work this out without more information - could
>>>>> you send us the error messages or stacktraces you are seeing?****
>>>>>
>>>>> ** **
>>>>>
>>>>> Sometimes, if tests fail when run as a group but pass individually, it
>>>>> may mean the unit tests are sharing state which is usually a bad thing.
>>>>> Each unit test should be completely independent and any variables / objects
>>>>> used reset or recreated each time. ****
>>>>>
>>>>> ** **
>>>>>
>>>>> The @Before annotation in JUnit is useful for this, as you can put
>>>>> initialisation code in a method have it run before each test. ****
>>>>>
>>>>> ** **
>>>>>
>>>>> Please send us some more detail and I'd be happy to take a look. ****
>>>>>
>>>>> ** **
>>>>>
>>>>> Thanks,****
>>>>>
>>>>> Dave****
>>>>>
>>>>> ** **
>>>>>
>>>>> On 20 June 2012 04:57, Qian Ye <ye...@gmail.com> wrote:****
>>>>>
>>>>> Hi all:
>>>>>
>>>>> I use MRUnit in my project using hadoop/hbase. It works well at first.
>>>>> These days I came across a strange situation. Some unittest failed when I
>>>>> use "mvn test", but it can pass when I use "mvn test -Dtest=xxxxx". The
>>>>> mapreduce program which is tested by the unittest read from hdfs and write
>>>>> to a hbase table. Has anyone met the same situation? Thanks for any help.
>>>>>
>>>>> --
>>>>> With Regards!
>>>>>
>>>>> Ye, Qian****
>>>>>
>>>>> ** **
>>>>>
>>>>>
>>>>>
>>>>>
>>>>> --
>>>>> With Regards!
>>>>>
>>>>> Ye, Qian****
>>>>>
>>>>
>>>>
>>>
>>
>>
>> --
>> With Regards!
>>
>> Ye, Qian
>>
>>
>
>
> --
> With Regards!
>
> Ye, Qian
>
>

Re: Some unittest failed when I use "mvn test", but it can pass when I use "mvn test -Dtest=xxxxx"

Posted by Qian Ye <ye...@gmail.com>.
The problem still there ... -_-!
I ran "mvn test" today, and the same assertion failure came out again.
Anymore advice about it?


On Sun, Jun 24, 2012 at 1:11 PM, Qian Ye <ye...@gmail.com> wrote:

> Yes Dave, the setUp is only called once. I added cleanupTestDir() before
> shutdownMiniCluster() in tearDown, and the testcase group passed. However,
> I still don't understand the reason.
>
> On Fri, Jun 22, 2012 at 12:44 AM, Dave Beech <db...@apache.org> wrote:
>
>> Or maybe it's something in the /tmp/mr folder not being cleared properly??
>>
>>
>> On 21 June 2012 17:42, Dave Beech <db...@apache.org> wrote:
>>
>>> I don't think setUp would be called twice actually - I don't think JUnit
>>> would see the @Before annotation on the parent class, so calling
>>> super.setUp in that way is probably OK.
>>>
>>> It might be possible to use @BeforeClass and @AfterClass to start up and
>>> tear down the mini cluster once, which will no doubt make the tests run
>>> quicker but I'm not sure that's the issue here.
>>>
>>> If tests pass individually but fail as a group, there must be some
>>> unintended sharing of state *somewhere*.  You have createTable calls in the
>>> @Before setup method, so should you explicitly delete them again after each
>>> test? Apologies, I am not too experienced with testing HBase in this way.
>>>
>>>
>>> On 21 June 2012 15:25, Haijia Zhou <ha...@adobe.com> wrote:
>>>
>>>> I think your code is sort of messed up, some comments:****
>>>>
>>>> **1.       **Why not use @BeforeClass in the base class and make
>>>> ‘setUp()’ method static since it’s supposed to be one time thing****
>>>>
>>>> **2.       **What’s the point of having ‘setUP()’ in both classes and
>>>> calling parent class’s setUp() from child class’s setUp()****
>>>>
>>>> I would think in your case the MiniMRTestBase.setUp() will be called
>>>> at least twice for each test, that might cause the issue.****
>>>>
>>>> ** **
>>>>
>>>> *From:* Qian Ye [mailto:yeqian.zju@gmail.com]
>>>> *Sent:* Wednesday, June 20, 2012 11:54 PM
>>>> *To:* Dave Beech
>>>> *Cc:* user@mrunit.apache.org
>>>> *Subject:* Re: Some unittest failed when I use "mvn test", but it can
>>>> pass when I use "mvn test -Dtest=xxxxx"****
>>>>
>>>> ** **
>>>>
>>>> Thanks Dave, here is more details. I have a base class like this:
>>>>
>>>> public class MiniMRTestBase {
>>>>
>>>>     public final static HBaseTestingUtility util = new
>>>> HBaseTestingUtility();
>>>>
>>>>     @Before
>>>>     public void setUp() throws Exception {
>>>>
>>>>         util.getConfiguration().addResource("hbase-site-local.xml");
>>>>         util.getConfiguration().reloadConfiguration();
>>>>
>>>>         util.getConfiguration().set("mapred.local.dir", "/tmp/mr");
>>>>
>>>>         util.startMiniCluster(1);
>>>>     }
>>>>
>>>>     @After
>>>>     public void tearDown() throws Exception {
>>>>         util.shutdownMiniCluster();
>>>>     }
>>>> }
>>>>
>>>> and all the test case extend this class. In the subclass, I use this
>>>> setup function to create table in testing hbase cluster.
>>>>     @Before
>>>>     public void setUp() throws Exception {
>>>>         super.setUp();
>>>>         // create table
>>>>         installHistoryTbl = util.createTable(INSTALL_HISTORY,
>>>> INSTALL_CF);
>>>>         dailyLaunchIndexTbl = util.createTable(DAILY_LAUNCH_INDEX,
>>>> LAUNCH_CF);
>>>>         deviceInfoTbl = util.createTable(DEVICE_INFO, INFO_CF);
>>>>         appusercountTbl = util.createTable(APP_USER_COUNT, STAT_CF);
>>>>     }
>>>>
>>>> In my opinion, in this situation, test case in different testing
>>>> subclass should not affect others, that is when I use "mvn test", the
>>>> result should be the same as the result of "mvn test -Dtest=xxxxx". But
>>>> "mvn test" gave me a assertion failure. It is interesting that I have about
>>>> 80 test cases, and the assertion failure only occur in 1 test case. The
>>>> stack traces is,
>>>>
>>>> testHourlyMapReduceTempSvrTime(com.umeng.dp.mapreduce.HourlyProcedureMapReduceTest)
>>>> Time elapsed: 24.476 sec  <<< FAILURE!
>>>> java.lang.AssertionError: expected:<2012-03-20 17:00:28> but was:<null>
>>>>     at org.junit.Assert.fail(Assert.java:91)
>>>>     at org.junit.Assert.failNotEquals(Assert.java:645)
>>>>     at org.junit.Assert.assertEquals(Assert.java:126)
>>>>     at org.junit.Assert.assertEquals(Assert.java:145)
>>>>     at
>>>> com.umeng.dp.mapreduce.HourlyProcedureMapReduceTest.testHourlyMapReduceTempSvrTime(HourlyProcedureMapReduceTest.java:729)
>>>>     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
>>>>     at
>>>> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
>>>>     at
>>>> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
>>>>     at java.lang.reflect.Method.invoke(Method.java:597)
>>>>     at
>>>> org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)
>>>>     at
>>>> org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
>>>>     at
>>>> org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)
>>>>     at
>>>> org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
>>>>     at
>>>> org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28)
>>>>     at
>>>> org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:31)
>>>>     at
>>>> org.junit.runners.BlockJUnit4ClassRunner.runNotIgnored(BlockJUnit4ClassRunner.java:79)
>>>>     at
>>>> org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:71)
>>>>     at
>>>> org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:49)
>>>>     at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193)
>>>>     at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52)
>>>>     at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191)
>>>>     at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42)
>>>>     at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184)
>>>>     at org.junit.runners.ParentRunner.run(ParentRunner.java:236)
>>>>     at
>>>> org.apache.maven.surefire.junit4.JUnit4TestSet.execute(JUnit4TestSet.java:53)
>>>>     at
>>>> org.apache.maven.surefire.junit4.JUnit4Provider.executeTestSet(JUnit4Provider.java:123)
>>>>     at
>>>> org.apache.maven.surefire.junit4.JUnit4Provider.invoke(JUnit4Provider.java:104)
>>>>     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
>>>>     at
>>>> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
>>>>     at
>>>> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
>>>>     at java.lang.reflect.Method.invoke(Method.java:597)
>>>>     at
>>>> org.apache.maven.surefire.util.ReflectionUtils.invokeMethodWithArray(ReflectionUtils.java:164)
>>>>     at
>>>> org.apache.maven.surefire.booter.ProviderFactory$ProviderProxy.invoke(ProviderFactory.java:110)
>>>>     at
>>>> org.apache.maven.surefire.booter.SurefireStarter.invokeProvider(SurefireStarter.java:175)
>>>>     at
>>>> org.apache.maven.surefire.booter.SurefireStarter.runSuitesInProcessWhenForked(SurefireStarter.java:107)
>>>>     at
>>>> org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:68)
>>>> testHourlyMapReduceAccTypeCarrier(com.umeng.dp.mapreduce.HourlyProcedureMapReduceTest)
>>>> Time elapsed: 24.279 sec  <<< FAILURE!
>>>> java.lang.AssertionError: expected:<2g/3g> but was:<null>
>>>>     at org.junit.Assert.fail(Assert.java:91)
>>>>     at org.junit.Assert.failNotEquals(Assert.java:645)
>>>>     at org.junit.Assert.assertEquals(Assert.java:126)
>>>>     at org.junit.Assert.assertEquals(Assert.java:145)
>>>>     at
>>>> com.umeng.dp.mapreduce.HourlyProcedureMapReduceTest.testHourlyMapReduceAccTypeCarrier(HourlyProcedureMapReduceTest.java:761)
>>>>     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
>>>>     at
>>>> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
>>>>     at
>>>> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
>>>>     at java.lang.reflect.Method.invoke(Method.java:597)
>>>>     at
>>>> org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)
>>>>     at
>>>> org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
>>>>     at
>>>> org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)
>>>>     at
>>>> org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
>>>>     at
>>>> org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28)
>>>>     at
>>>> org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:31)
>>>>     at
>>>> org.junit.runners.BlockJUnit4ClassRunner.runNotIgnored(BlockJUnit4ClassRunner.java:79)
>>>>     at
>>>> org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:71)
>>>>     at
>>>> org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:49)
>>>>     at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193)
>>>>     at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52)
>>>>     at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191)
>>>>     at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42)
>>>>     at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184)
>>>>     at org.junit.runners.ParentRunner.run(ParentRunner.java:236)
>>>>     at
>>>> org.apache.maven.surefire.junit4.JUnit4TestSet.execute(JUnit4TestSet.java:53)
>>>>     at
>>>> org.apache.maven.surefire.junit4.JUnit4Provider.executeTestSet(JUnit4Provider.java:123)
>>>>     at
>>>> org.apache.maven.surefire.junit4.JUnit4Provider.invoke(JUnit4Provider.java:104)
>>>>     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
>>>>     at
>>>> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
>>>>     at
>>>> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
>>>>     at java.lang.reflect.Method.invoke(Method.java:597)
>>>>     at
>>>> org.apache.maven.surefire.util.ReflectionUtils.invokeMethodWithArray(ReflectionUtils.java:164)
>>>>     at
>>>> org.apache.maven.surefire.booter.ProviderFactory$ProviderProxy.invoke(ProviderFactory.java:110)
>>>>     at
>>>> org.apache.maven.surefire.booter.SurefireStarter.invokeProvider(SurefireStarter.java:175)
>>>>     at
>>>> org.apache.maven.surefire.booter.SurefireStarter.runSuitesInProcessWhenForked(SurefireStarter.java:107)
>>>>     at
>>>> org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:68)
>>>>
>>>> Thanks for ur help!
>>>>
>>>> ****
>>>>
>>>> On Wed, Jun 20, 2012 at 4:07 PM, Dave Beech <db...@apache.org> wrote:*
>>>> ***
>>>>
>>>> Hi Qian, ****
>>>>
>>>> ** **
>>>>
>>>> It may be difficult to work this out without more information - could
>>>> you send us the error messages or stacktraces you are seeing?****
>>>>
>>>> ** **
>>>>
>>>> Sometimes, if tests fail when run as a group but pass individually, it
>>>> may mean the unit tests are sharing state which is usually a bad thing.
>>>> Each unit test should be completely independent and any variables / objects
>>>> used reset or recreated each time. ****
>>>>
>>>> ** **
>>>>
>>>> The @Before annotation in JUnit is useful for this, as you can put
>>>> initialisation code in a method have it run before each test. ****
>>>>
>>>> ** **
>>>>
>>>> Please send us some more detail and I'd be happy to take a look. ****
>>>>
>>>> ** **
>>>>
>>>> Thanks,****
>>>>
>>>> Dave****
>>>>
>>>> ** **
>>>>
>>>> On 20 June 2012 04:57, Qian Ye <ye...@gmail.com> wrote:****
>>>>
>>>> Hi all:
>>>>
>>>> I use MRUnit in my project using hadoop/hbase. It works well at first.
>>>> These days I came across a strange situation. Some unittest failed when I
>>>> use "mvn test", but it can pass when I use "mvn test -Dtest=xxxxx". The
>>>> mapreduce program which is tested by the unittest read from hdfs and write
>>>> to a hbase table. Has anyone met the same situation? Thanks for any help.
>>>>
>>>> --
>>>> With Regards!
>>>>
>>>> Ye, Qian****
>>>>
>>>> ** **
>>>>
>>>>
>>>>
>>>>
>>>> --
>>>> With Regards!
>>>>
>>>> Ye, Qian****
>>>>
>>>
>>>
>>
>
>
> --
> With Regards!
>
> Ye, Qian
>
>


-- 
With Regards!

Ye, Qian

Re: Some unittest failed when I use "mvn test", but it can pass when I use "mvn test -Dtest=xxxxx"

Posted by Qian Ye <ye...@gmail.com>.
Yes Dave, the setUp is only called once. I added cleanupTestDir() before
shutdownMiniCluster() in tearDown, and the testcase group passed. However,
I still don't understand the reason.

On Fri, Jun 22, 2012 at 12:44 AM, Dave Beech <db...@apache.org> wrote:

> Or maybe it's something in the /tmp/mr folder not being cleared properly??
>
>
> On 21 June 2012 17:42, Dave Beech <db...@apache.org> wrote:
>
>> I don't think setUp would be called twice actually - I don't think JUnit
>> would see the @Before annotation on the parent class, so calling
>> super.setUp in that way is probably OK.
>>
>> It might be possible to use @BeforeClass and @AfterClass to start up and
>> tear down the mini cluster once, which will no doubt make the tests run
>> quicker but I'm not sure that's the issue here.
>>
>> If tests pass individually but fail as a group, there must be some
>> unintended sharing of state *somewhere*.  You have createTable calls in the
>> @Before setup method, so should you explicitly delete them again after each
>> test? Apologies, I am not too experienced with testing HBase in this way.
>>
>>
>> On 21 June 2012 15:25, Haijia Zhou <ha...@adobe.com> wrote:
>>
>>> I think your code is sort of messed up, some comments:****
>>>
>>> **1.       **Why not use @BeforeClass in the base class and make
>>> ‘setUp()’ method static since it’s supposed to be one time thing****
>>>
>>> **2.       **What’s the point of having ‘setUP()’ in both classes and
>>> calling parent class’s setUp() from child class’s setUp()****
>>>
>>> I would think in your case the MiniMRTestBase.setUp() will be called at
>>> least twice for each test, that might cause the issue.****
>>>
>>> ** **
>>>
>>> *From:* Qian Ye [mailto:yeqian.zju@gmail.com]
>>> *Sent:* Wednesday, June 20, 2012 11:54 PM
>>> *To:* Dave Beech
>>> *Cc:* user@mrunit.apache.org
>>> *Subject:* Re: Some unittest failed when I use "mvn test", but it can
>>> pass when I use "mvn test -Dtest=xxxxx"****
>>>
>>> ** **
>>>
>>> Thanks Dave, here is more details. I have a base class like this:
>>>
>>> public class MiniMRTestBase {
>>>
>>>     public final static HBaseTestingUtility util = new
>>> HBaseTestingUtility();
>>>
>>>     @Before
>>>     public void setUp() throws Exception {
>>>
>>>         util.getConfiguration().addResource("hbase-site-local.xml");
>>>         util.getConfiguration().reloadConfiguration();
>>>
>>>         util.getConfiguration().set("mapred.local.dir", "/tmp/mr");
>>>
>>>         util.startMiniCluster(1);
>>>     }
>>>
>>>     @After
>>>     public void tearDown() throws Exception {
>>>         util.shutdownMiniCluster();
>>>     }
>>> }
>>>
>>> and all the test case extend this class. In the subclass, I use this
>>> setup function to create table in testing hbase cluster.
>>>     @Before
>>>     public void setUp() throws Exception {
>>>         super.setUp();
>>>         // create table
>>>         installHistoryTbl = util.createTable(INSTALL_HISTORY,
>>> INSTALL_CF);
>>>         dailyLaunchIndexTbl = util.createTable(DAILY_LAUNCH_INDEX,
>>> LAUNCH_CF);
>>>         deviceInfoTbl = util.createTable(DEVICE_INFO, INFO_CF);
>>>         appusercountTbl = util.createTable(APP_USER_COUNT, STAT_CF);
>>>     }
>>>
>>> In my opinion, in this situation, test case in different testing
>>> subclass should not affect others, that is when I use "mvn test", the
>>> result should be the same as the result of "mvn test -Dtest=xxxxx". But
>>> "mvn test" gave me a assertion failure. It is interesting that I have about
>>> 80 test cases, and the assertion failure only occur in 1 test case. The
>>> stack traces is,
>>>
>>> testHourlyMapReduceTempSvrTime(com.umeng.dp.mapreduce.HourlyProcedureMapReduceTest)
>>> Time elapsed: 24.476 sec  <<< FAILURE!
>>> java.lang.AssertionError: expected:<2012-03-20 17:00:28> but was:<null>
>>>     at org.junit.Assert.fail(Assert.java:91)
>>>     at org.junit.Assert.failNotEquals(Assert.java:645)
>>>     at org.junit.Assert.assertEquals(Assert.java:126)
>>>     at org.junit.Assert.assertEquals(Assert.java:145)
>>>     at
>>> com.umeng.dp.mapreduce.HourlyProcedureMapReduceTest.testHourlyMapReduceTempSvrTime(HourlyProcedureMapReduceTest.java:729)
>>>     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
>>>     at
>>> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
>>>     at
>>> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
>>>     at java.lang.reflect.Method.invoke(Method.java:597)
>>>     at
>>> org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)
>>>     at
>>> org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
>>>     at
>>> org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)
>>>     at
>>> org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
>>>     at
>>> org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28)
>>>     at
>>> org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:31)
>>>     at
>>> org.junit.runners.BlockJUnit4ClassRunner.runNotIgnored(BlockJUnit4ClassRunner.java:79)
>>>     at
>>> org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:71)
>>>     at
>>> org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:49)
>>>     at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193)
>>>     at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52)
>>>     at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191)
>>>     at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42)
>>>     at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184)
>>>     at org.junit.runners.ParentRunner.run(ParentRunner.java:236)
>>>     at
>>> org.apache.maven.surefire.junit4.JUnit4TestSet.execute(JUnit4TestSet.java:53)
>>>     at
>>> org.apache.maven.surefire.junit4.JUnit4Provider.executeTestSet(JUnit4Provider.java:123)
>>>     at
>>> org.apache.maven.surefire.junit4.JUnit4Provider.invoke(JUnit4Provider.java:104)
>>>     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
>>>     at
>>> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
>>>     at
>>> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
>>>     at java.lang.reflect.Method.invoke(Method.java:597)
>>>     at
>>> org.apache.maven.surefire.util.ReflectionUtils.invokeMethodWithArray(ReflectionUtils.java:164)
>>>     at
>>> org.apache.maven.surefire.booter.ProviderFactory$ProviderProxy.invoke(ProviderFactory.java:110)
>>>     at
>>> org.apache.maven.surefire.booter.SurefireStarter.invokeProvider(SurefireStarter.java:175)
>>>     at
>>> org.apache.maven.surefire.booter.SurefireStarter.runSuitesInProcessWhenForked(SurefireStarter.java:107)
>>>     at
>>> org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:68)
>>> testHourlyMapReduceAccTypeCarrier(com.umeng.dp.mapreduce.HourlyProcedureMapReduceTest)
>>> Time elapsed: 24.279 sec  <<< FAILURE!
>>> java.lang.AssertionError: expected:<2g/3g> but was:<null>
>>>     at org.junit.Assert.fail(Assert.java:91)
>>>     at org.junit.Assert.failNotEquals(Assert.java:645)
>>>     at org.junit.Assert.assertEquals(Assert.java:126)
>>>     at org.junit.Assert.assertEquals(Assert.java:145)
>>>     at
>>> com.umeng.dp.mapreduce.HourlyProcedureMapReduceTest.testHourlyMapReduceAccTypeCarrier(HourlyProcedureMapReduceTest.java:761)
>>>     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
>>>     at
>>> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
>>>     at
>>> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
>>>     at java.lang.reflect.Method.invoke(Method.java:597)
>>>     at
>>> org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)
>>>     at
>>> org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
>>>     at
>>> org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)
>>>     at
>>> org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
>>>     at
>>> org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28)
>>>     at
>>> org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:31)
>>>     at
>>> org.junit.runners.BlockJUnit4ClassRunner.runNotIgnored(BlockJUnit4ClassRunner.java:79)
>>>     at
>>> org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:71)
>>>     at
>>> org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:49)
>>>     at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193)
>>>     at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52)
>>>     at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191)
>>>     at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42)
>>>     at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184)
>>>     at org.junit.runners.ParentRunner.run(ParentRunner.java:236)
>>>     at
>>> org.apache.maven.surefire.junit4.JUnit4TestSet.execute(JUnit4TestSet.java:53)
>>>     at
>>> org.apache.maven.surefire.junit4.JUnit4Provider.executeTestSet(JUnit4Provider.java:123)
>>>     at
>>> org.apache.maven.surefire.junit4.JUnit4Provider.invoke(JUnit4Provider.java:104)
>>>     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
>>>     at
>>> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
>>>     at
>>> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
>>>     at java.lang.reflect.Method.invoke(Method.java:597)
>>>     at
>>> org.apache.maven.surefire.util.ReflectionUtils.invokeMethodWithArray(ReflectionUtils.java:164)
>>>     at
>>> org.apache.maven.surefire.booter.ProviderFactory$ProviderProxy.invoke(ProviderFactory.java:110)
>>>     at
>>> org.apache.maven.surefire.booter.SurefireStarter.invokeProvider(SurefireStarter.java:175)
>>>     at
>>> org.apache.maven.surefire.booter.SurefireStarter.runSuitesInProcessWhenForked(SurefireStarter.java:107)
>>>     at
>>> org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:68)
>>>
>>> Thanks for ur help!
>>>
>>> ****
>>>
>>> On Wed, Jun 20, 2012 at 4:07 PM, Dave Beech <db...@apache.org> wrote:**
>>> **
>>>
>>> Hi Qian, ****
>>>
>>> ** **
>>>
>>> It may be difficult to work this out without more information - could
>>> you send us the error messages or stacktraces you are seeing?****
>>>
>>> ** **
>>>
>>> Sometimes, if tests fail when run as a group but pass individually, it
>>> may mean the unit tests are sharing state which is usually a bad thing.
>>> Each unit test should be completely independent and any variables / objects
>>> used reset or recreated each time. ****
>>>
>>> ** **
>>>
>>> The @Before annotation in JUnit is useful for this, as you can put
>>> initialisation code in a method have it run before each test. ****
>>>
>>> ** **
>>>
>>> Please send us some more detail and I'd be happy to take a look. ****
>>>
>>> ** **
>>>
>>> Thanks,****
>>>
>>> Dave****
>>>
>>> ** **
>>>
>>> On 20 June 2012 04:57, Qian Ye <ye...@gmail.com> wrote:****
>>>
>>> Hi all:
>>>
>>> I use MRUnit in my project using hadoop/hbase. It works well at first.
>>> These days I came across a strange situation. Some unittest failed when I
>>> use "mvn test", but it can pass when I use "mvn test -Dtest=xxxxx". The
>>> mapreduce program which is tested by the unittest read from hdfs and write
>>> to a hbase table. Has anyone met the same situation? Thanks for any help.
>>>
>>> --
>>> With Regards!
>>>
>>> Ye, Qian****
>>>
>>> ** **
>>>
>>>
>>>
>>>
>>> --
>>> With Regards!
>>>
>>> Ye, Qian****
>>>
>>
>>
>


-- 
With Regards!

Ye, Qian

Re: Some unittest failed when I use "mvn test", but it can pass when I use "mvn test -Dtest=xxxxx"

Posted by Dave Beech <db...@apache.org>.
Or maybe it's something in the /tmp/mr folder not being cleared properly??

On 21 June 2012 17:42, Dave Beech <db...@apache.org> wrote:

> I don't think setUp would be called twice actually - I don't think JUnit
> would see the @Before annotation on the parent class, so calling
> super.setUp in that way is probably OK.
>
> It might be possible to use @BeforeClass and @AfterClass to start up and
> tear down the mini cluster once, which will no doubt make the tests run
> quicker but I'm not sure that's the issue here.
>
> If tests pass individually but fail as a group, there must be some
> unintended sharing of state *somewhere*.  You have createTable calls in the
> @Before setup method, so should you explicitly delete them again after each
> test? Apologies, I am not too experienced with testing HBase in this way.
>
>
> On 21 June 2012 15:25, Haijia Zhou <ha...@adobe.com> wrote:
>
>> I think your code is sort of messed up, some comments:****
>>
>> **1.       **Why not use @BeforeClass in the base class and make
>> ‘setUp()’ method static since it’s supposed to be one time thing****
>>
>> **2.       **What’s the point of having ‘setUP()’ in both classes and
>> calling parent class’s setUp() from child class’s setUp()****
>>
>> I would think in your case the MiniMRTestBase.setUp() will be called at
>> least twice for each test, that might cause the issue.****
>>
>> ** **
>>
>> *From:* Qian Ye [mailto:yeqian.zju@gmail.com]
>> *Sent:* Wednesday, June 20, 2012 11:54 PM
>> *To:* Dave Beech
>> *Cc:* user@mrunit.apache.org
>> *Subject:* Re: Some unittest failed when I use "mvn test", but it can
>> pass when I use "mvn test -Dtest=xxxxx"****
>>
>> ** **
>>
>> Thanks Dave, here is more details. I have a base class like this:
>>
>> public class MiniMRTestBase {
>>
>>     public final static HBaseTestingUtility util = new
>> HBaseTestingUtility();
>>
>>     @Before
>>     public void setUp() throws Exception {
>>
>>         util.getConfiguration().addResource("hbase-site-local.xml");
>>         util.getConfiguration().reloadConfiguration();
>>
>>         util.getConfiguration().set("mapred.local.dir", "/tmp/mr");
>>
>>         util.startMiniCluster(1);
>>     }
>>
>>     @After
>>     public void tearDown() throws Exception {
>>         util.shutdownMiniCluster();
>>     }
>> }
>>
>> and all the test case extend this class. In the subclass, I use this
>> setup function to create table in testing hbase cluster.
>>     @Before
>>     public void setUp() throws Exception {
>>         super.setUp();
>>         // create table
>>         installHistoryTbl = util.createTable(INSTALL_HISTORY, INSTALL_CF);
>>         dailyLaunchIndexTbl = util.createTable(DAILY_LAUNCH_INDEX,
>> LAUNCH_CF);
>>         deviceInfoTbl = util.createTable(DEVICE_INFO, INFO_CF);
>>         appusercountTbl = util.createTable(APP_USER_COUNT, STAT_CF);
>>     }
>>
>> In my opinion, in this situation, test case in different testing subclass
>> should not affect others, that is when I use "mvn test", the result should
>> be the same as the result of "mvn test -Dtest=xxxxx". But "mvn test" gave
>> me a assertion failure. It is interesting that I have about 80 test cases,
>> and the assertion failure only occur in 1 test case. The stack traces is,
>>
>> testHourlyMapReduceTempSvrTime(com.umeng.dp.mapreduce.HourlyProcedureMapReduceTest)
>> Time elapsed: 24.476 sec  <<< FAILURE!
>> java.lang.AssertionError: expected:<2012-03-20 17:00:28> but was:<null>
>>     at org.junit.Assert.fail(Assert.java:91)
>>     at org.junit.Assert.failNotEquals(Assert.java:645)
>>     at org.junit.Assert.assertEquals(Assert.java:126)
>>     at org.junit.Assert.assertEquals(Assert.java:145)
>>     at
>> com.umeng.dp.mapreduce.HourlyProcedureMapReduceTest.testHourlyMapReduceTempSvrTime(HourlyProcedureMapReduceTest.java:729)
>>     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
>>     at
>> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
>>     at
>> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
>>     at java.lang.reflect.Method.invoke(Method.java:597)
>>     at
>> org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)
>>     at
>> org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
>>     at
>> org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)
>>     at
>> org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
>>     at
>> org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28)
>>     at
>> org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:31)
>>     at
>> org.junit.runners.BlockJUnit4ClassRunner.runNotIgnored(BlockJUnit4ClassRunner.java:79)
>>     at
>> org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:71)
>>     at
>> org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:49)
>>     at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193)
>>     at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52)
>>     at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191)
>>     at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42)
>>     at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184)
>>     at org.junit.runners.ParentRunner.run(ParentRunner.java:236)
>>     at
>> org.apache.maven.surefire.junit4.JUnit4TestSet.execute(JUnit4TestSet.java:53)
>>     at
>> org.apache.maven.surefire.junit4.JUnit4Provider.executeTestSet(JUnit4Provider.java:123)
>>     at
>> org.apache.maven.surefire.junit4.JUnit4Provider.invoke(JUnit4Provider.java:104)
>>     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
>>     at
>> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
>>     at
>> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
>>     at java.lang.reflect.Method.invoke(Method.java:597)
>>     at
>> org.apache.maven.surefire.util.ReflectionUtils.invokeMethodWithArray(ReflectionUtils.java:164)
>>     at
>> org.apache.maven.surefire.booter.ProviderFactory$ProviderProxy.invoke(ProviderFactory.java:110)
>>     at
>> org.apache.maven.surefire.booter.SurefireStarter.invokeProvider(SurefireStarter.java:175)
>>     at
>> org.apache.maven.surefire.booter.SurefireStarter.runSuitesInProcessWhenForked(SurefireStarter.java:107)
>>     at
>> org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:68)
>> testHourlyMapReduceAccTypeCarrier(com.umeng.dp.mapreduce.HourlyProcedureMapReduceTest)
>> Time elapsed: 24.279 sec  <<< FAILURE!
>> java.lang.AssertionError: expected:<2g/3g> but was:<null>
>>     at org.junit.Assert.fail(Assert.java:91)
>>     at org.junit.Assert.failNotEquals(Assert.java:645)
>>     at org.junit.Assert.assertEquals(Assert.java:126)
>>     at org.junit.Assert.assertEquals(Assert.java:145)
>>     at
>> com.umeng.dp.mapreduce.HourlyProcedureMapReduceTest.testHourlyMapReduceAccTypeCarrier(HourlyProcedureMapReduceTest.java:761)
>>     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
>>     at
>> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
>>     at
>> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
>>     at java.lang.reflect.Method.invoke(Method.java:597)
>>     at
>> org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)
>>     at
>> org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
>>     at
>> org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)
>>     at
>> org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
>>     at
>> org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28)
>>     at
>> org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:31)
>>     at
>> org.junit.runners.BlockJUnit4ClassRunner.runNotIgnored(BlockJUnit4ClassRunner.java:79)
>>     at
>> org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:71)
>>     at
>> org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:49)
>>     at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193)
>>     at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52)
>>     at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191)
>>     at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42)
>>     at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184)
>>     at org.junit.runners.ParentRunner.run(ParentRunner.java:236)
>>     at
>> org.apache.maven.surefire.junit4.JUnit4TestSet.execute(JUnit4TestSet.java:53)
>>     at
>> org.apache.maven.surefire.junit4.JUnit4Provider.executeTestSet(JUnit4Provider.java:123)
>>     at
>> org.apache.maven.surefire.junit4.JUnit4Provider.invoke(JUnit4Provider.java:104)
>>     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
>>     at
>> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
>>     at
>> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
>>     at java.lang.reflect.Method.invoke(Method.java:597)
>>     at
>> org.apache.maven.surefire.util.ReflectionUtils.invokeMethodWithArray(ReflectionUtils.java:164)
>>     at
>> org.apache.maven.surefire.booter.ProviderFactory$ProviderProxy.invoke(ProviderFactory.java:110)
>>     at
>> org.apache.maven.surefire.booter.SurefireStarter.invokeProvider(SurefireStarter.java:175)
>>     at
>> org.apache.maven.surefire.booter.SurefireStarter.runSuitesInProcessWhenForked(SurefireStarter.java:107)
>>     at
>> org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:68)
>>
>> Thanks for ur help!
>>
>> ****
>>
>> On Wed, Jun 20, 2012 at 4:07 PM, Dave Beech <db...@apache.org> wrote:***
>> *
>>
>> Hi Qian, ****
>>
>> ** **
>>
>> It may be difficult to work this out without more information - could you
>> send us the error messages or stacktraces you are seeing?****
>>
>> ** **
>>
>> Sometimes, if tests fail when run as a group but pass individually, it
>> may mean the unit tests are sharing state which is usually a bad thing.
>> Each unit test should be completely independent and any variables / objects
>> used reset or recreated each time. ****
>>
>> ** **
>>
>> The @Before annotation in JUnit is useful for this, as you can put
>> initialisation code in a method have it run before each test. ****
>>
>> ** **
>>
>> Please send us some more detail and I'd be happy to take a look. ****
>>
>> ** **
>>
>> Thanks,****
>>
>> Dave****
>>
>> ** **
>>
>> On 20 June 2012 04:57, Qian Ye <ye...@gmail.com> wrote:****
>>
>> Hi all:
>>
>> I use MRUnit in my project using hadoop/hbase. It works well at first.
>> These days I came across a strange situation. Some unittest failed when I
>> use "mvn test", but it can pass when I use "mvn test -Dtest=xxxxx". The
>> mapreduce program which is tested by the unittest read from hdfs and write
>> to a hbase table. Has anyone met the same situation? Thanks for any help.
>>
>> --
>> With Regards!
>>
>> Ye, Qian****
>>
>> ** **
>>
>>
>>
>>
>> --
>> With Regards!
>>
>> Ye, Qian****
>>
>
>

Re: Some unittest failed when I use "mvn test", but it can pass when I use "mvn test -Dtest=xxxxx"

Posted by Dave Beech <db...@apache.org>.
I don't think setUp would be called twice actually - I don't think JUnit
would see the @Before annotation on the parent class, so calling
super.setUp in that way is probably OK.

It might be possible to use @BeforeClass and @AfterClass to start up and
tear down the mini cluster once, which will no doubt make the tests run
quicker but I'm not sure that's the issue here.

If tests pass individually but fail as a group, there must be some
unintended sharing of state *somewhere*.  You have createTable calls in the
@Before setup method, so should you explicitly delete them again after each
test? Apologies, I am not too experienced with testing HBase in this way.

On 21 June 2012 15:25, Haijia Zhou <ha...@adobe.com> wrote:

> I think your code is sort of messed up, some comments:****
>
> **1.       **Why not use @BeforeClass in the base class and make
> ‘setUp()’ method static since it’s supposed to be one time thing****
>
> **2.       **What’s the point of having ‘setUP()’ in both classes and
> calling parent class’s setUp() from child class’s setUp()****
>
> I would think in your case the MiniMRTestBase.setUp() will be called at
> least twice for each test, that might cause the issue.****
>
> ** **
>
> *From:* Qian Ye [mailto:yeqian.zju@gmail.com]
> *Sent:* Wednesday, June 20, 2012 11:54 PM
> *To:* Dave Beech
> *Cc:* user@mrunit.apache.org
> *Subject:* Re: Some unittest failed when I use "mvn test", but it can
> pass when I use "mvn test -Dtest=xxxxx"****
>
> ** **
>
> Thanks Dave, here is more details. I have a base class like this:
>
> public class MiniMRTestBase {
>
>     public final static HBaseTestingUtility util = new
> HBaseTestingUtility();
>
>     @Before
>     public void setUp() throws Exception {
>
>         util.getConfiguration().addResource("hbase-site-local.xml");
>         util.getConfiguration().reloadConfiguration();
>
>         util.getConfiguration().set("mapred.local.dir", "/tmp/mr");
>
>         util.startMiniCluster(1);
>     }
>
>     @After
>     public void tearDown() throws Exception {
>         util.shutdownMiniCluster();
>     }
> }
>
> and all the test case extend this class. In the subclass, I use this setup
> function to create table in testing hbase cluster.
>     @Before
>     public void setUp() throws Exception {
>         super.setUp();
>         // create table
>         installHistoryTbl = util.createTable(INSTALL_HISTORY, INSTALL_CF);
>         dailyLaunchIndexTbl = util.createTable(DAILY_LAUNCH_INDEX,
> LAUNCH_CF);
>         deviceInfoTbl = util.createTable(DEVICE_INFO, INFO_CF);
>         appusercountTbl = util.createTable(APP_USER_COUNT, STAT_CF);
>     }
>
> In my opinion, in this situation, test case in different testing subclass
> should not affect others, that is when I use "mvn test", the result should
> be the same as the result of "mvn test -Dtest=xxxxx". But "mvn test" gave
> me a assertion failure. It is interesting that I have about 80 test cases,
> and the assertion failure only occur in 1 test case. The stack traces is,
>
> testHourlyMapReduceTempSvrTime(com.umeng.dp.mapreduce.HourlyProcedureMapReduceTest)
> Time elapsed: 24.476 sec  <<< FAILURE!
> java.lang.AssertionError: expected:<2012-03-20 17:00:28> but was:<null>
>     at org.junit.Assert.fail(Assert.java:91)
>     at org.junit.Assert.failNotEquals(Assert.java:645)
>     at org.junit.Assert.assertEquals(Assert.java:126)
>     at org.junit.Assert.assertEquals(Assert.java:145)
>     at
> com.umeng.dp.mapreduce.HourlyProcedureMapReduceTest.testHourlyMapReduceTempSvrTime(HourlyProcedureMapReduceTest.java:729)
>     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
>     at
> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
>     at
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
>     at java.lang.reflect.Method.invoke(Method.java:597)
>     at
> org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)
>     at
> org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
>     at
> org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)
>     at
> org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
>     at
> org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28)
>     at
> org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:31)
>     at
> org.junit.runners.BlockJUnit4ClassRunner.runNotIgnored(BlockJUnit4ClassRunner.java:79)
>     at
> org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:71)
>     at
> org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:49)
>     at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193)
>     at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52)
>     at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191)
>     at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42)
>     at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184)
>     at org.junit.runners.ParentRunner.run(ParentRunner.java:236)
>     at
> org.apache.maven.surefire.junit4.JUnit4TestSet.execute(JUnit4TestSet.java:53)
>     at
> org.apache.maven.surefire.junit4.JUnit4Provider.executeTestSet(JUnit4Provider.java:123)
>     at
> org.apache.maven.surefire.junit4.JUnit4Provider.invoke(JUnit4Provider.java:104)
>     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
>     at
> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
>     at
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
>     at java.lang.reflect.Method.invoke(Method.java:597)
>     at
> org.apache.maven.surefire.util.ReflectionUtils.invokeMethodWithArray(ReflectionUtils.java:164)
>     at
> org.apache.maven.surefire.booter.ProviderFactory$ProviderProxy.invoke(ProviderFactory.java:110)
>     at
> org.apache.maven.surefire.booter.SurefireStarter.invokeProvider(SurefireStarter.java:175)
>     at
> org.apache.maven.surefire.booter.SurefireStarter.runSuitesInProcessWhenForked(SurefireStarter.java:107)
>     at
> org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:68)
> testHourlyMapReduceAccTypeCarrier(com.umeng.dp.mapreduce.HourlyProcedureMapReduceTest)
> Time elapsed: 24.279 sec  <<< FAILURE!
> java.lang.AssertionError: expected:<2g/3g> but was:<null>
>     at org.junit.Assert.fail(Assert.java:91)
>     at org.junit.Assert.failNotEquals(Assert.java:645)
>     at org.junit.Assert.assertEquals(Assert.java:126)
>     at org.junit.Assert.assertEquals(Assert.java:145)
>     at
> com.umeng.dp.mapreduce.HourlyProcedureMapReduceTest.testHourlyMapReduceAccTypeCarrier(HourlyProcedureMapReduceTest.java:761)
>     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
>     at
> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
>     at
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
>     at java.lang.reflect.Method.invoke(Method.java:597)
>     at
> org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)
>     at
> org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
>     at
> org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)
>     at
> org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
>     at
> org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28)
>     at
> org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:31)
>     at
> org.junit.runners.BlockJUnit4ClassRunner.runNotIgnored(BlockJUnit4ClassRunner.java:79)
>     at
> org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:71)
>     at
> org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:49)
>     at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193)
>     at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52)
>     at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191)
>     at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42)
>     at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184)
>     at org.junit.runners.ParentRunner.run(ParentRunner.java:236)
>     at
> org.apache.maven.surefire.junit4.JUnit4TestSet.execute(JUnit4TestSet.java:53)
>     at
> org.apache.maven.surefire.junit4.JUnit4Provider.executeTestSet(JUnit4Provider.java:123)
>     at
> org.apache.maven.surefire.junit4.JUnit4Provider.invoke(JUnit4Provider.java:104)
>     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
>     at
> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
>     at
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
>     at java.lang.reflect.Method.invoke(Method.java:597)
>     at
> org.apache.maven.surefire.util.ReflectionUtils.invokeMethodWithArray(ReflectionUtils.java:164)
>     at
> org.apache.maven.surefire.booter.ProviderFactory$ProviderProxy.invoke(ProviderFactory.java:110)
>     at
> org.apache.maven.surefire.booter.SurefireStarter.invokeProvider(SurefireStarter.java:175)
>     at
> org.apache.maven.surefire.booter.SurefireStarter.runSuitesInProcessWhenForked(SurefireStarter.java:107)
>     at
> org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:68)
>
> Thanks for ur help!
>
> ****
>
> On Wed, Jun 20, 2012 at 4:07 PM, Dave Beech <db...@apache.org> wrote:****
>
> Hi Qian, ****
>
> ** **
>
> It may be difficult to work this out without more information - could you
> send us the error messages or stacktraces you are seeing?****
>
> ** **
>
> Sometimes, if tests fail when run as a group but pass individually, it may
> mean the unit tests are sharing state which is usually a bad thing. Each
> unit test should be completely independent and any variables / objects used
> reset or recreated each time. ****
>
> ** **
>
> The @Before annotation in JUnit is useful for this, as you can put
> initialisation code in a method have it run before each test. ****
>
> ** **
>
> Please send us some more detail and I'd be happy to take a look. ****
>
> ** **
>
> Thanks,****
>
> Dave****
>
> ** **
>
> On 20 June 2012 04:57, Qian Ye <ye...@gmail.com> wrote:****
>
> Hi all:
>
> I use MRUnit in my project using hadoop/hbase. It works well at first.
> These days I came across a strange situation. Some unittest failed when I
> use "mvn test", but it can pass when I use "mvn test -Dtest=xxxxx". The
> mapreduce program which is tested by the unittest read from hdfs and write
> to a hbase table. Has anyone met the same situation? Thanks for any help.
>
> --
> With Regards!
>
> Ye, Qian****
>
> ** **
>
>
>
>
> --
> With Regards!
>
> Ye, Qian****
>

RE: Some unittest failed when I use "mvn test", but it can pass when I use "mvn test -Dtest=xxxxx"

Posted by Haijia Zhou <ha...@adobe.com>.
I think your code is sort of messed up, some comments:

1.       Why not use @BeforeClass in the base class and make ‘setUp()’ method static since it’s supposed to be one time thing

2.       What’s the point of having ‘setUP()’ in both classes and calling parent class’s setUp() from child class’s setUp()
I would think in your case the MiniMRTestBase.setUp() will be called at least twice for each test, that might cause the issue.

From: Qian Ye [mailto:yeqian.zju@gmail.com]
Sent: Wednesday, June 20, 2012 11:54 PM
To: Dave Beech
Cc: user@mrunit.apache.org
Subject: Re: Some unittest failed when I use "mvn test", but it can pass when I use "mvn test -Dtest=xxxxx"

Thanks Dave, here is more details. I have a base class like this:

public class MiniMRTestBase {

    public final static HBaseTestingUtility util = new HBaseTestingUtility();

    @Before
    public void setUp() throws Exception {

        util.getConfiguration().addResource("hbase-site-local.xml");
        util.getConfiguration().reloadConfiguration();

        util.getConfiguration().set("mapred.local.dir", "/tmp/mr");

        util.startMiniCluster(1);
    }

    @After
    public void tearDown() throws Exception {
        util.shutdownMiniCluster();
    }
}

and all the test case extend this class. In the subclass, I use this setup function to create table in testing hbase cluster.
    @Before
    public void setUp() throws Exception {
        super.setUp();
        // create table
        installHistoryTbl = util.createTable(INSTALL_HISTORY, INSTALL_CF);
        dailyLaunchIndexTbl = util.createTable(DAILY_LAUNCH_INDEX, LAUNCH_CF);
        deviceInfoTbl = util.createTable(DEVICE_INFO, INFO_CF);
        appusercountTbl = util.createTable(APP_USER_COUNT, STAT_CF);
    }

In my opinion, in this situation, test case in different testing subclass should not affect others, that is when I use "mvn test", the result should be the same as the result of "mvn test -Dtest=xxxxx". But "mvn test" gave me a assertion failure. It is interesting that I have about 80 test cases, and the assertion failure only occur in 1 test case. The stack traces is,

testHourlyMapReduceTempSvrTime(com.umeng.dp.mapreduce.HourlyProcedureMapReduceTest)  Time elapsed: 24.476 sec  <<< FAILURE!
java.lang.AssertionError: expected:<2012-03-20 17:00:28> but was:<null>
    at org.junit.Assert.fail(Assert.java:91)
    at org.junit.Assert.failNotEquals(Assert.java:645)
    at org.junit.Assert.assertEquals(Assert.java:126)
    at org.junit.Assert.assertEquals(Assert.java:145)
    at com.umeng.dp.mapreduce.HourlyProcedureMapReduceTest.testHourlyMapReduceTempSvrTime(HourlyProcedureMapReduceTest.java:729)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)
    at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
    at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)
    at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
    at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28)
    at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:31)
    at org.junit.runners.BlockJUnit4ClassRunner.runNotIgnored(BlockJUnit4ClassRunner.java:79)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:71)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:49)
    at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193)
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52)
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191)
    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42)
    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:236)
    at org.apache.maven.surefire.junit4.JUnit4TestSet.execute(JUnit4TestSet.java:53)
    at org.apache.maven.surefire.junit4.JUnit4Provider.executeTestSet(JUnit4Provider.java:123)
    at org.apache.maven.surefire.junit4.JUnit4Provider.invoke(JUnit4Provider.java:104)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.apache.maven.surefire.util.ReflectionUtils.invokeMethodWithArray(ReflectionUtils.java:164)
    at org.apache.maven.surefire.booter.ProviderFactory$ProviderProxy.invoke(ProviderFactory.java:110)
    at org.apache.maven.surefire.booter.SurefireStarter.invokeProvider(SurefireStarter.java:175)
    at org.apache.maven.surefire.booter.SurefireStarter.runSuitesInProcessWhenForked(SurefireStarter.java:107)
    at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:68)
testHourlyMapReduceAccTypeCarrier(com.umeng.dp.mapreduce.HourlyProcedureMapReduceTest)  Time elapsed: 24.279 sec  <<< FAILURE!
java.lang.AssertionError: expected:<2g/3g> but was:<null>
    at org.junit.Assert.fail(Assert.java:91)
    at org.junit.Assert.failNotEquals(Assert.java:645)
    at org.junit.Assert.assertEquals(Assert.java:126)
    at org.junit.Assert.assertEquals(Assert.java:145)
    at com.umeng.dp.mapreduce.HourlyProcedureMapReduceTest.testHourlyMapReduceAccTypeCarrier(HourlyProcedureMapReduceTest.java:761)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)
    at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
    at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)
    at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
    at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28)
    at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:31)
    at org.junit.runners.BlockJUnit4ClassRunner.runNotIgnored(BlockJUnit4ClassRunner.java:79)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:71)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:49)
    at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193)
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52)
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191)
    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42)
    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:236)
    at org.apache.maven.surefire.junit4.JUnit4TestSet.execute(JUnit4TestSet.java:53)
    at org.apache.maven.surefire.junit4.JUnit4Provider.executeTestSet(JUnit4Provider.java:123)
    at org.apache.maven.surefire.junit4.JUnit4Provider.invoke(JUnit4Provider.java:104)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.apache.maven.surefire.util.ReflectionUtils.invokeMethodWithArray(ReflectionUtils.java:164)
    at org.apache.maven.surefire.booter.ProviderFactory$ProviderProxy.invoke(ProviderFactory.java:110)
    at org.apache.maven.surefire.booter.SurefireStarter.invokeProvider(SurefireStarter.java:175)
    at org.apache.maven.surefire.booter.SurefireStarter.runSuitesInProcessWhenForked(SurefireStarter.java:107)
    at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:68)

Thanks for ur help!

On Wed, Jun 20, 2012 at 4:07 PM, Dave Beech <db...@apache.org>> wrote:
Hi Qian,

It may be difficult to work this out without more information - could you send us the error messages or stacktraces you are seeing?

Sometimes, if tests fail when run as a group but pass individually, it may mean the unit tests are sharing state which is usually a bad thing. Each unit test should be completely independent and any variables / objects used reset or recreated each time.

The @Before annotation in JUnit is useful for this, as you can put initialisation code in a method have it run before each test.

Please send us some more detail and I'd be happy to take a look.

Thanks,
Dave

On 20 June 2012 04:57, Qian Ye <ye...@gmail.com>> wrote:
Hi all:

I use MRUnit in my project using hadoop/hbase. It works well at first. These days I came across a strange situation. Some unittest failed when I use "mvn test", but it can pass when I use "mvn test -Dtest=xxxxx". The mapreduce program which is tested by the unittest read from hdfs and write to a hbase table. Has anyone met the same situation? Thanks for any help.

--
With Regards!

Ye, Qian




--
With Regards!

Ye, Qian

Re: Some unittest failed when I use "mvn test", but it can pass when I use "mvn test -Dtest=xxxxx"

Posted by Qian Ye <ye...@gmail.com>.
Thanks Dave, here is more details. I have a base class like this:

public class MiniMRTestBase {

    public final static HBaseTestingUtility util = new
HBaseTestingUtility();

    @Before
    public void setUp() throws Exception {

        util.getConfiguration().addResource("hbase-site-local.xml");
        util.getConfiguration().reloadConfiguration();

        util.getConfiguration().set("mapred.local.dir", "/tmp/mr");

        util.startMiniCluster(1);
    }

    @After
    public void tearDown() throws Exception {
        util.shutdownMiniCluster();
    }
}

and all the test case extend this class. In the subclass, I use this setup
function to create table in testing hbase cluster.
    @Before
    public void setUp() throws Exception {
        super.setUp();
        // create table
        installHistoryTbl = util.createTable(INSTALL_HISTORY, INSTALL_CF);
        dailyLaunchIndexTbl = util.createTable(DAILY_LAUNCH_INDEX,
LAUNCH_CF);
        deviceInfoTbl = util.createTable(DEVICE_INFO, INFO_CF);
        appusercountTbl = util.createTable(APP_USER_COUNT, STAT_CF);
    }

In my opinion, in this situation, test case in different testing subclass
should not affect others, that is when I use "mvn test", the result should
be the same as the result of "mvn test -Dtest=xxxxx". But "mvn test" gave
me a assertion failure. It is interesting that I have about 80 test cases,
and the assertion failure only occur in 1 test case. The stack traces is,

testHourlyMapReduceTempSvrTime(com.umeng.dp.mapreduce.HourlyProcedureMapReduceTest)
Time elapsed: 24.476 sec  <<< FAILURE!
java.lang.AssertionError: expected:<2012-03-20 17:00:28> but was:<null>
    at org.junit.Assert.fail(Assert.java:91)
    at org.junit.Assert.failNotEquals(Assert.java:645)
    at org.junit.Assert.assertEquals(Assert.java:126)
    at org.junit.Assert.assertEquals(Assert.java:145)
    at
com.umeng.dp.mapreduce.HourlyProcedureMapReduceTest.testHourlyMapReduceTempSvrTime(HourlyProcedureMapReduceTest.java:729)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at
org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)
    at
org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
    at
org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)
    at
org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
    at
org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28)
    at
org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:31)
    at
org.junit.runners.BlockJUnit4ClassRunner.runNotIgnored(BlockJUnit4ClassRunner.java:79)
    at
org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:71)
    at
org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:49)
    at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193)
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52)
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191)
    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42)
    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:236)
    at
org.apache.maven.surefire.junit4.JUnit4TestSet.execute(JUnit4TestSet.java:53)
    at
org.apache.maven.surefire.junit4.JUnit4Provider.executeTestSet(JUnit4Provider.java:123)
    at
org.apache.maven.surefire.junit4.JUnit4Provider.invoke(JUnit4Provider.java:104)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at
org.apache.maven.surefire.util.ReflectionUtils.invokeMethodWithArray(ReflectionUtils.java:164)
    at
org.apache.maven.surefire.booter.ProviderFactory$ProviderProxy.invoke(ProviderFactory.java:110)
    at
org.apache.maven.surefire.booter.SurefireStarter.invokeProvider(SurefireStarter.java:175)
    at
org.apache.maven.surefire.booter.SurefireStarter.runSuitesInProcessWhenForked(SurefireStarter.java:107)
    at
org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:68)
testHourlyMapReduceAccTypeCarrier(com.umeng.dp.mapreduce.HourlyProcedureMapReduceTest)
Time elapsed: 24.279 sec  <<< FAILURE!
java.lang.AssertionError: expected:<2g/3g> but was:<null>
    at org.junit.Assert.fail(Assert.java:91)
    at org.junit.Assert.failNotEquals(Assert.java:645)
    at org.junit.Assert.assertEquals(Assert.java:126)
    at org.junit.Assert.assertEquals(Assert.java:145)
    at
com.umeng.dp.mapreduce.HourlyProcedureMapReduceTest.testHourlyMapReduceAccTypeCarrier(HourlyProcedureMapReduceTest.java:761)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at
org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)
    at
org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
    at
org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)
    at
org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
    at
org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28)
    at
org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:31)
    at
org.junit.runners.BlockJUnit4ClassRunner.runNotIgnored(BlockJUnit4ClassRunner.java:79)
    at
org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:71)
    at
org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:49)
    at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193)
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52)
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191)
    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42)
    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:236)
    at
org.apache.maven.surefire.junit4.JUnit4TestSet.execute(JUnit4TestSet.java:53)
    at
org.apache.maven.surefire.junit4.JUnit4Provider.executeTestSet(JUnit4Provider.java:123)
    at
org.apache.maven.surefire.junit4.JUnit4Provider.invoke(JUnit4Provider.java:104)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at
org.apache.maven.surefire.util.ReflectionUtils.invokeMethodWithArray(ReflectionUtils.java:164)
    at
org.apache.maven.surefire.booter.ProviderFactory$ProviderProxy.invoke(ProviderFactory.java:110)
    at
org.apache.maven.surefire.booter.SurefireStarter.invokeProvider(SurefireStarter.java:175)
    at
org.apache.maven.surefire.booter.SurefireStarter.runSuitesInProcessWhenForked(SurefireStarter.java:107)
    at
org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:68)

Thanks for ur help!


On Wed, Jun 20, 2012 at 4:07 PM, Dave Beech <db...@apache.org> wrote:

> Hi Qian,
>
> It may be difficult to work this out without more information - could you
> send us the error messages or stacktraces you are seeing?
>
> Sometimes, if tests fail when run as a group but pass individually, it may
> mean the unit tests are sharing state which is usually a bad thing. Each
> unit test should be completely independent and any variables / objects used
> reset or recreated each time.
>
> The @Before annotation in JUnit is useful for this, as you can put
> initialisation code in a method have it run before each test.
>
> Please send us some more detail and I'd be happy to take a look.
>
> Thanks,
> Dave
>
>
> On 20 June 2012 04:57, Qian Ye <ye...@gmail.com> wrote:
>
>> Hi all:
>>
>> I use MRUnit in my project using hadoop/hbase. It works well at first.
>> These days I came across a strange situation. Some unittest failed when I
>> use "mvn test", but it can pass when I use "mvn test -Dtest=xxxxx". The
>> mapreduce program which is tested by the unittest read from hdfs and write
>> to a hbase table. Has anyone met the same situation? Thanks for any help.
>>
>> --
>> With Regards!
>>
>> Ye, Qian
>>
>>
>


-- 
With Regards!

Ye, Qian

Re: Some unittest failed when I use "mvn test", but it can pass when I use "mvn test -Dtest=xxxxx"

Posted by Dave Beech <db...@apache.org>.
Hi Qian,

It may be difficult to work this out without more information - could you
send us the error messages or stacktraces you are seeing?

Sometimes, if tests fail when run as a group but pass individually, it may
mean the unit tests are sharing state which is usually a bad thing. Each
unit test should be completely independent and any variables / objects used
reset or recreated each time.

The @Before annotation in JUnit is useful for this, as you can put
initialisation code in a method have it run before each test.

Please send us some more detail and I'd be happy to take a look.

Thanks,
Dave

On 20 June 2012 04:57, Qian Ye <ye...@gmail.com> wrote:

> Hi all:
>
> I use MRUnit in my project using hadoop/hbase. It works well at first.
> These days I came across a strange situation. Some unittest failed when I
> use "mvn test", but it can pass when I use "mvn test -Dtest=xxxxx". The
> mapreduce program which is tested by the unittest read from hdfs and write
> to a hbase table. Has anyone met the same situation? Thanks for any help.
>
> --
> With Regards!
>
> Ye, Qian
>
>