bluelinelabs / Conductor

A small, yet full-featured framework that allows building View-based Android applications
Apache License 2.0
3.9k stars 343 forks source link

Test to ensure identical code #461

Closed EricKuck closed 4 years ago

EricKuck commented 6 years ago

I'm working on a system that will allow Conductor to get lifecycle events from a support lib fragment if it's available, else fall back to a native fragment. In order to do this, I've had to create two nearly identical classes. I'd like to make a test to make sure they don't accidentally diverge in the future. Does anyone have a good idea on how to write a test that compares the source of two files?

FWIW the files in question are AndroidXHelper.java and PlatformHelper.java, both of which are found here: https://github.com/bluelinelabs/Conductor/tree/feature/androidx_backing/conductor/src/main/java/com/bluelinelabs/conductor/internal/lifecyclehandler

PaulWoitaschek commented 6 years ago

What do you want to test?

Do you want to test the API surface? Or do you want to test the behavior?

In case it's the behavior, we can just write a test for the LifeCycleHandler and run it once for the AndroidX and once for the Framework one.

EricKuck commented 6 years ago

The behavior is very difficult to test. For example, there's no way that I know of to ensure that requesting permission was successful. I'm pretty comfortable trusting that Google's implementation works, so I believe it would be sufficient to ensure the actual code in the 2 classes remains in sync.

What are your thoughts on that?