Closed rekire closed 2 years ago
In my opinion you should check first if you are running on Android before executing Android specific code.
I am not sure why this doesn't work for you. How do you invoke the unit tests?
I like the idea of fallback to a fixed DNS server, but why just one IPv4 and IPv6?
Hardcoded DNS servers are a sensitive topic due the privacy implications. I tend to change MiniDNS so that they are not populated by default, and provide convenience methods like addGoogleDnsServersAsFallback()
. Furthermore there is currently no method to modify the hardcoded server set (you can do it via reflection though). Please also check the existing issues around hardcoded servers, like #72 and #102.
Thank you for your answer. After reviewing my code I found out that it is not crashing, but it is logging that exception. However since I still get the error logged that PlatformDetection
seems to be not bulletproof. Might be a check for Class.forName("org.junit.Test")
could fix it.
To be honest I just executed the test from Android Studio, I would guess that this executes in the background e.g. gradle test task.
I think what basically happens is that Android Studio executes the unit tests in an Android(-ish) environment, so that PlatformDetection.isAndroid()returns
true. However modern Android versions to no longer provide access to
android.os.SystemProperties`. Hence the exception.
Might be a check for
Class.forName("org.junit.Test")
could fix it.
How would that fix it?
That code could detect if junit is present and therefor not on a real device, however your solution is much better.
I'm evaluating this library for a project and I started using it in a UnitTest, but it crashes:
In my opinion you should check first if you are running on Android before executing Android specific code. I just want to quote the first sentence of the readme: "MiniDNS [...] is a DNS library for Android and Java SE." A unit test falls in my opinion in that case.
I like the idea of fallback to a fixed DNS server, but why just one IPv4 and IPv6? Google has 2 of both and there are also public alternatives like 1.1.1.1 or 9.9.9.9
When I find some free time I will create a PR in order to fix that. If anyone else is quicker then go on, that part is no rocket science.