PileProject / drive

The drive project
Other
5 stars 4 forks source link

Hotfix/execution bugs #46

Closed tiwanari closed 8 years ago

tiwanari commented 8 years ago

I checked #3 and fortunately the issue was (almost) solved 🎉

However, unfortunately, there are many bugs in some classes:

tiwanari commented 8 years ago

Sorry, I forgot adding null checks and to commit it (yeah, actually they are related to #3).

mandaiy commented 8 years ago

I did not check thoroughly your changes yet, but could you give here how you have tested your changes? I guess you did on a real robot and your tablet but in case you tested something other than on them.

And from my quick look, it seems easier to write test code for BlockProgrammingLogic. For NxtController if you remove the logic related to preferences, the class might be a test-friendly class.

tiwanari commented 8 years ago

Thanks for your comments :) I'll add more detail. Can you give me a moment?

tiwanari commented 8 years ago

Let me leave a note. Actually, as you said, most of the tests are running some programs. If you expected some test programs, to tell the truth, there were no concrete tests for them.

Firstly, I executed a blank program. At this point, my NXT hasn't sensors nor motors and the program successfully finished. This meant NxtControllerBuilder has finished his life as for motors because ExecutionThread makes commands to NXT motors after execution even if the program was blank. This lacks tests for sensors and I noticed NxtController has no null checks (this is the latest commit). With the change, #3 were surely solved.

However, ExecutionActivity didn't finish after execution, i.e., I couldn't go back to ProgrammingActivity. So, I dug into some classes such as ExecutionCondition because there is a possibility that the program was caught in a forever loop and, of course, I checked ExecutionActivityBase. I found most of the bugs manually in this stage.

The 4th commit is totally different from others. When I tried to run a program twice or more after fixing other bugs, I always caught a connection error. Tracing an execution, I found NxtMachine (mMachine) in NxtExecutionActivity hadn't been initialized and it caused an Exception. The lack of initialization was caused by the replacement of our old library with new one drivecommand and I decided to remove all uglily is_connected flags.

tiwanari commented 8 years ago

So, please give me a little time to add tests as you advised :)

tiwanari commented 8 years ago

Hi, I added some tests and fixed bugs.

BTW, how about using PowerMock? I have trouble testing final classes because they cannot be mocked/spied with Mockito.

Note: I don't like Whitebox.foo() in some test codes which is a part of Mockito ...

tiwanari commented 8 years ago

Thanks for comments, @myusak :)

So, I'll try to introduce PowerMock and make some more tests 💪

tiwanari commented 8 years ago

Hmm... I have trouble incorporating PowerMock because of a bug of DexMaker, poor compatibleness between PowerMock and DexMaker and so on :cyclone:

In short, using PowerMock along with DexMaker is impossible at present because of incompatibility (How to get Powermock to work with Dexmaker - Stack Overflow). Therefore, we cannot use PowerMock in androidTest.

tiwanari commented 8 years ago

Hi @myusak,

I fixed codes based on your advice, however, I couldn't use PowerMock at present because of the problem I mentioned above. This does not permit me to remove Whitebox and throw an Exception when null is passed to BluetoothCommunicator in order to do other tests because BluetoothDevice cannot be mocked and I should pass null to it in other tests.

At this point, I use @NonNull annotation as a workaround (compromise) but we may as well introduce a wrapper such as BluetoothDeviceProvider that can be mocked easily and thus enables testing BluetoothCommunicator.

What do you think? Should we do that in this PR? If so, I will also implement such class for NxtController as you pointed out.

mandaiy commented 8 years ago

I believe that actual code comes first before test code. I think the BluetoothComunicator should reject null object in its constructor and for now you may as well skip the test code. When the problem of Powermock is solved, we'd go for that.

I cannot agree with introducing such wrapper interface, since users of the communicator don't want to be bothered by that. Feel free to criticise me if my understanding is wrong.

tiwanari commented 8 years ago

Thanks for your comments :) I agreed and commented out all tests related to PowerMock. So, please review codes again 🙇

tiwanari commented 8 years ago

Hi @myusak,

Thank you for helpful comments :satisfied: I'll follow your advice :)

tiwanari commented 8 years ago

I fixed codes.

tiwanari commented 8 years ago

Hi @myusak,

I modified codes based on your helpful comments :star: I keep some topics discussed here as cards in Release project such as Guava and Finalizer.