Writing a gradle task to run Junits - linux

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.

Related

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...

Android test suite cannot be found

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

How to split a gradle task execution

In my gradle project I have a task Task1 with many dependency tasks Task1Dep1, Task1Dep2, Task1Dep3... Task1DepN.
Is there a way to split my execution of Task1 such that Task1Dep1, Task1Dep2 in one execution and then run Task1Dep3 ... Task2DepN in a second execution.
The reason I want to do this is that if this is possible then it will be a solution to a problem I posted about here: How to read latest property in property file that is updated earlier in gradle execution.
I was able to solve this issue as follows.
The gradle task I wanted to run was the release task for running the Townsfolk gradle-release plugin.
Normally this would be done as:
./gradlew release
Due to various issue sI ran into with the svn support in this plugin and using it with Android I had to split the underlying sub-tasks for this plugin as follows:
./gradlew -PusesSnapshot=true -PversionModified=true initScmPlugin checkCommitNeeded checkUpdateNeeded unSnapshotVersion
./gradlew -PusesSnapshot=true -PversionModified=true initScmPlugin confirmReleaseVersion checkSnapshotDependencies build preTagCommit
svn update
./gradlew -PusesSnapshot=true -PversionModified=true initScmPlugin createReleaseTag updateVersion commitNewVersion
I found the underlying tasks using:
./gradlew tasks --all

build succeeds publish fails visual studio 2012 WPF project

I have a WPF project that I normally publish for click once installs
The project stopped publishing about 3 days ago.
If I build and/or run the project from code it succeeds but publish fails.
Cannot publish because a project failed to build. 1 1 ProjectName
Could not find file 'obj\x86\Debug\ProjectName.exe'. ProjectName
Funny thing is if I look in the obj\x86\Debug folder it appears to put the ProjectName.exe in for a split second and then remove it again before failing.
The error in the output window is:
C:\Windows\Microsoft.NET\Framework\v4.0.30319\Microsoft.Common.targets(3075,5): error MSB3113: Could not find file 'obj\x86\Debug\ProjectName.exe'.
Error: Cannot publish because a project failed to build.
I've tried the normal stuff like cleaning, rebuilding, rebooting
After changing verbosity of build to diagnostics I got following information on the failure:
C:\Windows\Microsoft.NET\Framework\v4.0.30319\Microsoft.Common.targets(3075,5): error MSB3113: Could not find file 'obj\x86\Debug\ProjectName.exe'.
Done executing task "GenerateApplicationManifest" -- FAILED. (TaskId:147)
Done building target "GenerateApplicationManifest" in project "ProjectName.vbproj" -- FAILED.: (TargetId:166)
I was able to discover the answer by following paul's suggestion.
I increased the verbosity of the build project via Tools | Options | Projects And Solution | Build and Run | Project build output verbosity.
Once I looked at the more verbose build output fixing the problem was simple.
The verbose output gave me exactly where the publish was failing so I was then able to fix those problems.

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