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 9197981
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T22:11:17+00:00 2026-06-17T22:11:17+00:00

How do you unit test Parcelable? I created a Parcelable class, and wrote this

  • 0

How do you unit test Parcelable? I created a Parcelable class, and wrote this unit test

TestClass test = new TestClass();
Bundle bundle = new Bundle();
bundle.putParcelable("test", test);

TestClass testAfter = bundle.getParcelable("test");
assertEquals(testAfter.getStuff(), event1.getStuff());

I purposely try to fail the test by returning null in the createFromParcel(), but it seems to succeed. It looks like it doesn’t get parceled until it’s needed. How do I force the Bundle to..bundle?

  • 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-06-17T22:11:18+00:00Added an answer on June 17, 2026 at 10:11 pm

    I’ve found this link showing how you can unit test a parcelable object:
    http://stuffikeepforgettinghowtodo.blogspot.nl/2009/02/unit-test-your-custom-parcelable.html

    You can actually skip the Bundle if you don’t really need to include it like zorch did his suggestion. You would then get something like this:

    public void testTestClassParcelable(){
        TestClass test = new TestClass();
    
        // Obtain a Parcel object and write the parcelable object to it:
        Parcel parcel = Parcel.obtain();
        test.writeToParcel(parcel, 0);
    
        // After you're done with writing, you need to reset the parcel for reading:
        parcel.setDataPosition(0);
    
        // Reconstruct object from parcel and asserts:
        TestClass createdFromParcel = TestClass.CREATOR.createFromParcel(parcel);
        assertEquals(test, createdFromParcel);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this unit test in a Windows Store unit test project, using this
I am working on Unit Test using third party framework GHUnit, created project added
I set up a unit test as such: class UserViewTests(TestCase): def setUp(self): self.user_passwords =
I'm learning VS Unit test and tried this: [TestMethod()] public void calcTest() { double
I'm trying to unit test a service layer / application facade layer method. This
I have a unit test program i wrote to catch errors in the functions
I'm creating a unit test to try out the servlet I just created. @Test
I have unit test project called MyClassTest in TeamTest. This project has three TestMethods.
Assume I want to unit test a method with this signature: List<MyItem> getMyItems(); Assume
I have a Qt Unit test (sub)project, which generates me one class (with the

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.