AndroidJUnit4 Should have a public constructor











up vote
0
down vote

favorite












I'm trying to follow Android Developer Docs to write an Instrumented Unit Test, but, of course, it doesn't work. I am getting the error:



Custom runner class AndroidJUnit4 should have a public constructor with signature AndroidJUnit4(Class testClass)


when ever I run my example test:



package com.devetry.ytp

import android.content.Context
import android.support.test.InstrumentationRegistry
import android.support.test.rule.ActivityTestRule
import android.support.test.runner.AndroidJUnit4
import androidx.test.filters.LargeTest
import org.junit.Before
import org.junit.Test
import org.junit.runner.RunWith

import androidx.test.runner.AndroidJUnitRunner
import org.junit.Assert
import org.junit.Rule

@RunWith(AndroidJUnit4::class)
class ExampleAndroidTest {

/**
* VARIABLES
*/



/**
* LIFE CYCLE
*/


/**
* Example Android Test
*
* An example android test
*/
@Test
fun exampleAndroidTest() {
val context = InstrumentationRegistry.getTargetContext()
Assert.assertEquals("com.devetry.ytp", context.packageName)
}

}


I have tried tried multiple solutions to this specific error I found online, but like most things Android, the solution was either outdated or just simply didn't work. Unfortunately, of all of the solutions, I was unable to even recognize a common theme, thus leaving me stranded.



How can I resolve the error and just get an Instrumented Unit Tests to run?










share|improve this question






















  • stackoverflow.com/a/44478370/4936904
    – Pavneet_Singh
    Nov 21 at 17:26










  • @Pavneet_Singh yup, tried both of those. My Instrumented Test is in the AndroidTest folder and my configuration looks exactly the same...
    – Tanner Juby
    Nov 21 at 17:34















up vote
0
down vote

favorite












I'm trying to follow Android Developer Docs to write an Instrumented Unit Test, but, of course, it doesn't work. I am getting the error:



Custom runner class AndroidJUnit4 should have a public constructor with signature AndroidJUnit4(Class testClass)


when ever I run my example test:



package com.devetry.ytp

import android.content.Context
import android.support.test.InstrumentationRegistry
import android.support.test.rule.ActivityTestRule
import android.support.test.runner.AndroidJUnit4
import androidx.test.filters.LargeTest
import org.junit.Before
import org.junit.Test
import org.junit.runner.RunWith

import androidx.test.runner.AndroidJUnitRunner
import org.junit.Assert
import org.junit.Rule

@RunWith(AndroidJUnit4::class)
class ExampleAndroidTest {

/**
* VARIABLES
*/



/**
* LIFE CYCLE
*/


/**
* Example Android Test
*
* An example android test
*/
@Test
fun exampleAndroidTest() {
val context = InstrumentationRegistry.getTargetContext()
Assert.assertEquals("com.devetry.ytp", context.packageName)
}

}


I have tried tried multiple solutions to this specific error I found online, but like most things Android, the solution was either outdated or just simply didn't work. Unfortunately, of all of the solutions, I was unable to even recognize a common theme, thus leaving me stranded.



How can I resolve the error and just get an Instrumented Unit Tests to run?










share|improve this question






















  • stackoverflow.com/a/44478370/4936904
    – Pavneet_Singh
    Nov 21 at 17:26










  • @Pavneet_Singh yup, tried both of those. My Instrumented Test is in the AndroidTest folder and my configuration looks exactly the same...
    – Tanner Juby
    Nov 21 at 17:34













up vote
0
down vote

favorite









up vote
0
down vote

favorite











I'm trying to follow Android Developer Docs to write an Instrumented Unit Test, but, of course, it doesn't work. I am getting the error:



Custom runner class AndroidJUnit4 should have a public constructor with signature AndroidJUnit4(Class testClass)


when ever I run my example test:



package com.devetry.ytp

import android.content.Context
import android.support.test.InstrumentationRegistry
import android.support.test.rule.ActivityTestRule
import android.support.test.runner.AndroidJUnit4
import androidx.test.filters.LargeTest
import org.junit.Before
import org.junit.Test
import org.junit.runner.RunWith

import androidx.test.runner.AndroidJUnitRunner
import org.junit.Assert
import org.junit.Rule

@RunWith(AndroidJUnit4::class)
class ExampleAndroidTest {

/**
* VARIABLES
*/



/**
* LIFE CYCLE
*/


/**
* Example Android Test
*
* An example android test
*/
@Test
fun exampleAndroidTest() {
val context = InstrumentationRegistry.getTargetContext()
Assert.assertEquals("com.devetry.ytp", context.packageName)
}

}


I have tried tried multiple solutions to this specific error I found online, but like most things Android, the solution was either outdated or just simply didn't work. Unfortunately, of all of the solutions, I was unable to even recognize a common theme, thus leaving me stranded.



How can I resolve the error and just get an Instrumented Unit Tests to run?










share|improve this question













I'm trying to follow Android Developer Docs to write an Instrumented Unit Test, but, of course, it doesn't work. I am getting the error:



Custom runner class AndroidJUnit4 should have a public constructor with signature AndroidJUnit4(Class testClass)


when ever I run my example test:



package com.devetry.ytp

import android.content.Context
import android.support.test.InstrumentationRegistry
import android.support.test.rule.ActivityTestRule
import android.support.test.runner.AndroidJUnit4
import androidx.test.filters.LargeTest
import org.junit.Before
import org.junit.Test
import org.junit.runner.RunWith

import androidx.test.runner.AndroidJUnitRunner
import org.junit.Assert
import org.junit.Rule

@RunWith(AndroidJUnit4::class)
class ExampleAndroidTest {

/**
* VARIABLES
*/



/**
* LIFE CYCLE
*/


/**
* Example Android Test
*
* An example android test
*/
@Test
fun exampleAndroidTest() {
val context = InstrumentationRegistry.getTargetContext()
Assert.assertEquals("com.devetry.ytp", context.packageName)
}

}


I have tried tried multiple solutions to this specific error I found online, but like most things Android, the solution was either outdated or just simply didn't work. Unfortunately, of all of the solutions, I was unable to even recognize a common theme, thus leaving me stranded.



How can I resolve the error and just get an Instrumented Unit Tests to run?







android android-testing android-instrumentation






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 21 at 17:21









Tanner Juby

738




738












  • stackoverflow.com/a/44478370/4936904
    – Pavneet_Singh
    Nov 21 at 17:26










  • @Pavneet_Singh yup, tried both of those. My Instrumented Test is in the AndroidTest folder and my configuration looks exactly the same...
    – Tanner Juby
    Nov 21 at 17:34


















  • stackoverflow.com/a/44478370/4936904
    – Pavneet_Singh
    Nov 21 at 17:26










  • @Pavneet_Singh yup, tried both of those. My Instrumented Test is in the AndroidTest folder and my configuration looks exactly the same...
    – Tanner Juby
    Nov 21 at 17:34
















stackoverflow.com/a/44478370/4936904
– Pavneet_Singh
Nov 21 at 17:26




stackoverflow.com/a/44478370/4936904
– Pavneet_Singh
Nov 21 at 17:26












@Pavneet_Singh yup, tried both of those. My Instrumented Test is in the AndroidTest folder and my configuration looks exactly the same...
– Tanner Juby
Nov 21 at 17:34




@Pavneet_Singh yup, tried both of those. My Instrumented Test is in the AndroidTest folder and my configuration looks exactly the same...
– Tanner Juby
Nov 21 at 17:34

















active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53417512%2fandroidjunit4-should-have-a-public-constructor%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown






























active

oldest

votes













active

oldest

votes









active

oldest

votes






active

oldest

votes
















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.





Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


Please pay close attention to the following guidance:


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53417512%2fandroidjunit4-should-have-a-public-constructor%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

A CLEAN and SIMPLE way to add appendices to Table of Contents and bookmarks

Calculate evaluation metrics using cross_val_predict sklearn

Insert data from modal to MySQL (multiple modal on website)