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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T21:55:05+00:00 2026-06-14T21:55:05+00:00

I am new to junit testing. Can anyone help me , how to test

  • 0

I am new to junit testing.

Can anyone help me , how to test my SQLiteOpenHelper class.

Means what classes I have to implement and how to test my db and tables.
I am using Eclipse IDE.

  • 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-14T21:55:06+00:00Added an answer on June 14, 2026 at 9:55 pm

    As of API Level 24, RenamingDelegatingContext is deprecated. Another thread suggests to use Robolectric‘s RuntimeEnvironment.application as described in this Medium article.

    The old answer for reference:

    For a simple DatabaseHandler:

    public class MyDatabase extends SQLiteOpenHelper {
        private static final String DATABASE_NAME = "database.db";
        private static final int DATABASE_VERSION = 1;
    
        public MyDatabase(Context context){
            super(context, DATABASE_NAME, null, DATABASE_VERSION);
        }
    
        @Override
        public void onCreate(SQLiteDatabase db){
            // some code
        }
    
        @Override
        public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
            // some code
        }
    }
    

    I created an AndroidTestCase:

    public class DatabaseTest extends AndroidTestCase {
        private MyDatabase db;
    
        @Override
        public void setUp() throws Exception {
            super.setUp();
            RenamingDelegatingContext context = new RenamingDelegatingContext(getContext(), "test_");
            db = new MyDatabase(context);
        }
    
        @Override
        public void tearDown() throws Exception {
            db.close(); 
            super.tearDown();
        }
    
        //According to Zainodis annotation only for legacy and not valid with gradle>1.1:
        //@Test
        public void testAddEntry(){
            // Here I have my new database which is not connected to the standard database of the App
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am new to junit testing and I have the following test - public
I am very new using JUnit. I want to test some classes that implements
I am very new to JUnit testing, I am trying to test the following
I have set up a JUnit test that is testing a method called copy(File
I am new for Junit testing framework. Is it possible to test a flow
I am new to Java testing with JUnit. I have to work with Java
I have a Java JUnit 4 test and a generic class which creates a
I am new to JUnit and Android and good test documentation for working with
Unit testing is new to me, and I have this error I don't understand.
I am new to Java and junit. I have the following peice of code

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.