Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7577593
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T17:13:39+00:00 2026-05-30T17:13:39+00:00

I have an app that displays the Maidenhead grid square corresponding to that location.

  • 0

I have an app that displays the Maidenhead grid square corresponding to that location. I would like to write a unit test for this feature.

I have created a mock location provider. When I stick the mock provider into my app, I see the expected Maidenhead grid square on the display. When I stick the mock provider into my test project and check the view it never updates, even when I call Thread.sleep() or waitOnIdleSync().

I would directly test the method that computes the actual grid square but it is private, and there’s no way to test private methods. All the example code I have seen online for unit tests that check views is for apps like calculators, where activity is triggered by fake button presses.

Here is the code for the test:

    public void testMaidenhead() {
        // this is a single test which doesn't really validate the algorithm
        // identifying a bunch of edge cases would do that
        publishMockLocation();
        final String expectedMH = "CM87wk";
        // TODO: checking the textview does not work
        TextView mhValueView = (TextView) mActivity.findViewById(org.twilley.android.hfbeacon.R.id.maidenheadValue);
        String actualMH = mhValueView.getText().toString();
        // final String actualMH = mActivity.gridSquare(mLocation);
        assertEquals(expectedMH, actualMH);
    }

And here is the code for publishing the mock location:

    protected void publishMockLocation() {
        final double TEST_LONGITUDE = -122.084095;
        final double TEST_LATITUDE = 37.422006;
        final String TEST_PROVIDER = "test";
        final Location mLocation;
        final LocationManager mLocationManager;

        mLocationManager = (LocationManager) mActivity.getSystemService(Context.LOCATION_SERVICE);
        if (mLocationManager.getProvider(TEST_PROVIDER) != null) {
            mLocationManager.removeTestProvider(TEST_PROVIDER);
        }
        if (mLocationManager.getProvider(TEST_PROVIDER) == null) {
            mLocationManager.addTestProvider(TEST_PROVIDER, 
                false, //requiresNetwork,
                false, // requiresSatellite,
                false, // requiresCell,
                false, // hasMonetaryCost,
                false, // supportsAltitude,
                false, // supportsSpeed,
                false, // supportsBearing,
                android.location.Criteria.POWER_MEDIUM, // powerRequirement
                android.location.Criteria.ACCURACY_FINE); // accuracy
        }
        mLocation = new Location(TEST_PROVIDER);
        mLocation.setLatitude(TEST_LATITUDE);
        mLocation.setLongitude(TEST_LONGITUDE);
        mLocation.setTime(System.currentTimeMillis());
        mLocation.setAccuracy(25);
        mLocationManager.setTestProviderEnabled(TEST_PROVIDER, true);
        mLocationManager.setTestProviderStatus(TEST_PROVIDER, LocationProvider.AVAILABLE, null, System.currentTimeMillis());
        mLocationManager.setTestProviderLocation(TEST_PROVIDER, mLocation);
    }

Any help would be dearly appreciated. Thank you in advance!

Jack.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T17:13:40+00:00Added an answer on May 30, 2026 at 5:13 pm

    Unit testing would not be to make your phone fake its GPS location so it shows you the Maidenhead for the location you want to test. Unit testing would be: write a function that takes WGS84 GPS coordinates and outputs Maidenhead, and write a couple of tests for a series of input locations and outputs to make sure your function works as you need.

    Testing the actual Android activity would be integration or acceptance testing, but the actual coordinate to Maidenhead functionality should work as you unit tested it.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an app that displays transcripts, something like this myapp.com/transcript/1234 The transcripts are
I have an App that downloads and displays images from URL's. This works fine
I have a test winforms app with ThreadExceptionHandler that displays a message box when
I have an Orbeon app that displays a table of test results and in
I have setup a basic test app that displays a view containing a label,
I have a simple OpenGL app that displays arbitrary 3D models. I'd like to
I have an app that displays a map of the user's location and tracks
I have a UITableView in my app that displays some Location objects which I
I have an App that displays thousands of Pin annotations on a google map
I have an app that displays a splash screen. The splash screen activity creates

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.