Android test suite cannot be found - android-studio

i've renamed my test folder to "test". Before it was set to AndroidTest and everything works. But i have a task from my superior that the test folder must be called "test". After i renamed the folder to test in android studio the test stopped running so i went into the run configuration for the test and specified teh package name but that did not help. Here are some details on issue:
and here is the build configuration i am running for the test:
The manifest does not have anything about test in it. This is just a dummy project i made. Do i need to enter something in the manifest ?

After reading the article provided in the comments i thought i'd share how one might resolved the issue:
Android studio does not know how to respond to our test runner unless we tell it. so i made a gradle task like the following:
when you run this gradle task it will run all test cases.
To explain, here we will cleanTest (which cleans all previous tests) then we will run the test task (its like doing gradle test on command line to run test). The test dont run again if they are successful so if you give it the option of --rerun-tasks then it will return the same test task. As for the --tests * option its used to specify which tests you want to run. in my case it was everything but you can specify a class path or even down to the method level here. very useful. so its like running this on the command line: gradle test --rerun-tasks

Related

Writing a gradle task to run Junits

I am a newbee to gradle. The task at hand is to add a new gradle task that can run all the junits in the project and show a summary like which testcases passed, failed,skipped etc.
gradle version used is 4.8.1 and junit4.11
The project structure is like this:
Myproject
|_____api
| |_____src
| |_____main
| |_____test
| |____java
|_____cli
|_____src
|_____main
|_____test
|____java
I am able to run the individual tests from intelliJ.
There is a "test" method defined in the build.gradle of "cli" but I am not sure it runs. With command "gradle clean test" the build is successfull but I see no test results.
test {
include '*/cli/src/test/java/testsuites/*'
exclude '*/cli/src/test/java/com/myproject/mytool/*'
}
I have tried to add dependency and other things that I got from googling and at stackoverflow but of no use.Nothing seems to be working out.Can anyone help me to understand the basic steps and checks that I need to follow to create a gradle task for running junits? any help is appriciated.

Android studio: How to re run unit test automatically at file change?

Coming from Typescript using Jest there I could send the --watch flag and every time I changed the test file the test will automatically run.
Is there something similar with Android Studio using JUnit5 ?
This can be achieved using Gradle 6.7 or higher. Adding --watch-fs enables Gradle's fs watcher. You might want to also include -Dorg.gradle.vfs.verbose=true to get more information about the virtual fs state and events it received.
Example to run tests:
./gradlew --watch-fs -Dorg.gradle.vfs.verbose=true test

Build - Make module/project uses wrong build type

As long as I used android studio 3.1 everything was working fine. But after the recent update to 3.2 I see following behaviour:
calling "build"/"make module" leads to execution of Executing tasks: [assemble]
calling "build"/"make project" leads to the same, assemble task is executed as well
Before the update I was able to exectue the correct assemble task (like assembleDebug<...>).
Does anyone know where I can correct this? Can I somehow check which task is bound to those menus and edit them? I have this problem with one project only...
Currently I have to manually execute the gradle task to get what I want, menu entries seem to be broken...
Setup
I am using flavours
I have selected a build variant of debug type, all my modules are set to debug as well:
apps build variant: devWithoutTestWithAccessibilityDebug
all other modules build variant: debug
Current solution
I use my own gradle tasks for my most common development build like following for now:
task runDev (type: Exec, dependsOn: 'installDevWithoutTestWithAccessibilityDebug') {
commandLine android.getAdbExe().toString(), "shell",
"monkey",
"-p", "com.my.app.debug",
"-c", "android.intent.category.LAUNCHER", "1"
}
What I tried
Clean project like following:
delete ALL *.iml files
delete .gradle and .idea folder
delete all temp files
import project again
sync project with gradle files
create app run configuration again and start it
Still I end with the same result...

Temporary files on Travis

I have a Javascript project which uses Grunt for build process, QUnit for tests, Blanket for code coverage and a custom Grunt task to convert coverage results into LCOV files, sended to Coveralls. Everything running on TravisCI.
the project : https://github.com/mistic100/jQuery-QueryBuilder
my Grunt task : https://github.com/mistic100/grunt-qunit-blanket-lcov
So what should happen is that npm test runs QUnit+Blanket tests in a PhantomJS process and in the meanwhile, coverage results are saved in .coverage-results/all.lcov.
After a successfull build, grunt coveralls sends this file to Coveralls.
And my problem is here, the task does not find the file, although when I test on my computer it does.
see the last Travis log: https://travis-ci.org/mistic100/jQuery-QueryBuilder#L389
The only thing I can think about is that the file, for some reason, is deleted once npm test is finished. Is it possible ?
edit
so this has nothing to do with Travis but with my Grunt task where I use absolute paths thinking it's relative paths (I still don't know why it doesn't append on Windows though)
The only thing I can think about is that the file, for some reason, is deleted once npm test is finished. Is it possible ?
No, lifecycle-wise the build artefacts are still present, when running after_success commands.
The gruntfile.js configures force true and defines path - no issue here.
This should work.
I would suggest to throw in some commands to check the folders and files on Travis.
- sudo ls -alh /home/travis/build/mistic100/jQuery-QueryBuilder/*
- sudo ls -alh /home/travis/build/mistic100/jQuery-QueryBuilder/.coverage-results/*
Maybe you spot a permission issue during folder and file creation.
But that's my only guess.

How to Run a Spock Test inside Eclipse

I try to run my first Spock Test inside Eclipse, and it does not work.
I added all the Maven dependencies and plugins in my pom.xml, but when I run my test with jUnit, there is a popup windows with this Warning message : "No jUnit tests found".
Did you already seen this kind of message ?
What config has to be done, in order to run a Spock Test inside Eclipse ?
Thanks a lot.
Its same as running Junit test cases.
Right click on the class and run as 4Junit Test runner. see below for complete configurations and running the spock test.
Running Spock Framework with Eclipse, Gradle, Groovy: Source -
Krzysztof Goralski, blog
-Install Gradle Plugin, check it here
-Install Groovy-Eclipse for Juno or Indigo from Eclipse Marketplace (or maybe Groovy/Grails Tool Suite for Eclipse)
-Install Spock Plugin From Eclipse Marketplace if you want, check it here
-Import Project to Eclipse through Gradle Import
-Add these lines to build.gradle:
apply plugin: ‘groovy’
testCompile ‘org.spockframework:spock-spring:1.0-groovy-2.3’ (for Spring)
this is quite important, version can make some conflicts
-After this *.groovy and *.gradle files will problably looks different, Syntax colour highlightning etc. Remember that you can right click on for eg. build.gradle -> Open with -> Open With Minimalist gradle Editor etc.
-Probably you will need to make additional folder for *.groovy test files
Create new *.groovy file, class
-Basic test example, extends Specification from Spock framework and needs specific Annotations when running with Spring
-Now you can run it with JUnit from Eclipse
For integration tests you can’t use #RunWith(SpringJUnit4ClassRunner.class), and Context should looks like here #ContextConfiguration(locations = [ “/restTestContext.xml” ]) , not {} braces, but [ ]
-Spock can be used for Mocks too. Something like this: Subscriber subscriber1 = Mock() , subscriber1.isActive() >> true , So, remember >> operator for mocks.
Right click on the project > Properties > Java Build Bath > Add External Jars and add spock-core-0.6-groovy-1.8.jar and check if Groovy Libraries are there in Build Path or not. If not click on Add Library and select Groovy Runtime Libraries and restart Eclipse. Now you should be able to run. If still can't Run then try creating New Configuration and change the Test runner to Junit4 and Run it...
Check if the folder your tests are in is a source folder.

Resources