android-ago icon indicating copy to clipboard operation
android-ago copied to clipboard

Add automated tests

Open curioustechizen opened this issue 8 years ago • 4 comments

Introduce an abstraction for getting time (instead of using System.currentTimeMillis()) directly in RTTV.

Build on top of this to add automated tests, especially around scheduling the UpdateTimeTask.

curioustechizen avatar Apr 27 '17 12:04 curioustechizen

Hello,

I'm in the process of adding unit tests, but I'm running into a couple dependency problems. Adding some setters and hooking into the init seems a possible solution, but I wanted to run it by you first (and introduce myself I suppose).

For example, RTTV currently instantiates its own handler for use on line 190. Adding a setter to set a Mockito variant would be helpful for unit testing, plus having everything instantiate in init() would add some consistency

private void init(Context context, AttributeSet attrs) {
    ...
    
    if (mHandler == null) {
        mHandler = new Handler();
    }
}

======================= EDIT: There's an ongoing problem with tight coupling that makes testing difficult (impossible?) without an API change, e.g. Handler.post() invoked by init(), which is invoked in constructor. Consider moving setReferenceTime() to separate "start()" function?

kwak123 avatar Feb 15 '18 16:02 kwak123

@kwak123 Thanks for taking a stab at this. I will not have time to look into it in detail for a couple of weeks though. That said, your inputs are appreciated and I will follow up on your comments when I have time.

curioustechizen avatar Feb 21 '18 03:02 curioustechizen

No problem. If you're fine with it, I can open up a PR with a possible approach

kwak123 avatar Feb 21 '18 03:02 kwak123

I'd prefer to discuss first before you put in the effort to make a PR!

curioustechizen avatar Feb 21 '18 04:02 curioustechizen