I have parts of my app that I don't want to run if we're running Android unit tests, so I want to surround them with something like
if (!BuildConfig.TESTING) {
// Code here that I don't want to run during tests.
}
Is it possible to populate this BuildConfig
flag depending on whether the connectedAndroidTest
gradle task is used? Is this a sane way of approaching this problem?
BuildConfig
contents are determined by build type. Why aren't you just basing your decision on the build type? – LattaDEBUG
vsRELEASE
? There is some code like things that report to our analytics server that we want running in both DEBUG and RELEASE mode, but not when running through tests. – Racerdebug
to be for the unit tests and create a third build type for whatever other role you are using fordebug
at present that requires analytics work. – LattaIsTest
class in the test source package, and then use reflection to check if the classIsTest
exists. – Disquisition