last day (16 days later) » 

14:49
2
A: How to test element of custom sdk android unit test

Michael DoddUnit tests are mainly about testing an individual class in isolation, so that you can check if individual public methods of a class behave as you intend them to, and continue to do so if you change that class' code in the future. Let's say you have a class like this: public class UtilityFunction...

hey thank for your answer, i have error : its not found InstrumentationRegistry what i should add ?
Firstly, is your test class in the androidTest folder? Secondly, have you got @RunWith(AndroidJUnit4.class) at the top of your class? (Above public class AndroidTest)
sorry i found, i have wrong declaration for this in build.gradle
No worries, if it's all working for you and this answer's helped, then please upvote and accept (✔)
i trying to use ur example : i get this error java.lang.IllegalStateException: No instrumentation registered! Must run under a registering instrumentation. Realy i dont undertand how to run them.
14:49
You haven't defined testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" in your build.gradle file. Take some time to read through the documentation and make sure you follow all the steps.
Unbelivable , im going by tutorial , official tutorial and i got error on line @RunWith(AndroidJUnit4.class) why why its happened ? If use JUnit4.class than no error. But instrumentation not working. omg 9((((
Does it not have the option to import the class with Alt+Enter?
and do you have all the AndroidTestCompile entries in your build.gradle?
Hi @M
Hi @MichaelDodd
i cant receive context anything not working
i dont need instrumental testing. but i need context in simple unit cases
15:08
Why does your class need a context? What context methods is it calling?
sdk init have a method where context required
how i can check if for example AudioManager init true ?
its my code
very simple i get them from tutorial which not working
i add cunstructor/constructor with params nothing to work
and error
say : i need make request to url (server) there are need context , how i can make a test without context ?
15:25
Can you show me your build.gradle?
the com.android.support entries near the bottom need to be androidTestCompile, not testCompile
prntscr.com/hn082o if set as u say
somewhere i read about testCompile thats why i set testCompile
And is your test class in the test folder or the androidTest folder?
12
A: java.lang.Exception: Custom runner class AndroidJUnit4 should have a public constructor with signature AndroidJUnit4(Class testClass)

David RawsonCause 1: placing tests in the wrong folder This error can be replicated by making a new Application with the default template in Android Studio and copying the auto-generated ExampleInstrumentedTest from the androidTest folder to the test folder: Here's what the error looks like: Note that...

testCompile is only for unit tests that don't rely on the Android framework (and thus can be run without an Android device)
since you use Context it needs to be in androidTest and using androidTestCompile in bild.gradle
15:40
its look like instrumental test
Can you show me your project structure? Where the test file is located?
androidTets
androidTest
Do a Gradle sync?
16:23
yes
i think i fixed it , now i have some passed tests
but its look like every test - i should init my small sdk. And its instrumental test , my device going crazy with screen . its show on 0.01 second and closed. I cant understand how to set wait screen
16:34
That's deliberate
Each test is done in isolation
The activity starts, a single test is run, and the activity ends
this makes sure each test is run from an identical starting point
It's all automated, there should be no need for input from you, that's the point
but does it seem to be working ok for you now?
Realy i dont know, is it ok if i need every @Test - init my sdk ?
and i have a url request - i cant understand how to pass him
That entirely depends on what your code does and how you want to test it
Figuring out how to test code is half of the problem
say : i have request , i need wait 30 seconds meanwhile he will complete
If you're testing web requests, that's getting into the realms of OkHttp and mock web servers
I'd recommend sticking with the basics for now, and maybe look into Mockito and get familiar with testing before you move on to something more advanced like that
its good recomendation
16:44
try testing other parts of your app that don't rely on network connections
but... as always but
simple tests work ok
i dont have problem with simple tests. But when i start testing "advanced" i stuck here
in logs its just request to url and stop.
Again, without seeing your code, I can't help you much there, and either way, we're drifting into the scope of a new question, not the original one asked
if u need reputation
i can spam somewhere and accept your answers
its not a problem
you just one person who helping me
All I can say is just practice. Don't do too much too soon else you won't understand it
 
3 hours later…
19:36
@Peter If this answer and subsequent chat has helped you get on the right track, then please click the ✔ icon below the score. If you're having further issues, post a new question and I can take a look.

  last day (16 days later) »