How to show test info in console using androidStudio and gradle? - testing

I just created a project with androidStudio, I added the structure of tests, and can see the test results with the format of xml/html.
My question is how could I see the test output in console?
You can check the project on https://github.com/kolyjjj/process_killer

It seems the output will show in console when you write Local unit tests. Located at module-name/src/test/java/.
But in Instrumented tests,Located at module-name/src/androidTest/java/,output did't show in the console,It will show in logcat.

Related

Cucumber-JVM: Cucumber After hook executed two times/twice

I"m implemnet Cucumber Testng for learning purposes. I"m realizes that #After hook method is executed twice. I can confirm it with debugging set and test report output. I"m only execute 1 feature file and my test report has two same class names.
Do you guys know why?
There is warning in the feature file called Multiple Definitions "Volare Collector Home Page opens in browser".
Please help. Thanks.
Please download my source code from this link.

How to display build error messages in TeamCity when using cake build scripts

Having a CI pipeline that is using Teamcity and Octopus deploy and build scripts written with Cake I want to be able to display the error messages that generated by the build script.
Now the message displayed is:
Exit code 1 (new)
In order to be able to see the real error message one must view the build log and parse it.
So, even when using build script, I want to be able to display the build results in overview page and the list of errors like in the following picture:
I know that Cake provides support for integration with TeamCity, but the documentation and examples are not that straightforward.
Ca anyone provide some helpful information regarding this subject?
Cake implements a method to be able to write a build problem
TeamCityProvider​.BuildProblem(string, ​string)
Looking at the source code for this provider, I can determine that this will build up a string to output that conforms to the build script interaction specified in the TeamCity documentation, specifically reporting the build problem
##teamcity[buildProblem description='<description>' identity='<identity>']
by calling BuildProblem("Some message", "Some identity") this will output
##teamcity[buildProblem description='Some Message' identity='Some identity']
TeamCity should then fail the build and display the message as per the documentation;
To fail a build directly from the build script, a build problem has be reported. Build problems appear on the Build Results page and also affect the build status text.
You need to edit the cake build scripts to properly trap the exception and call the above method, so it will write to the output stream correctly.
I can replicate this behaviour using a PowerShell script to write the buildProblem message to the ouput stream
This will then show the very message in the build results on the overview page
Hope this helps

RSpec: How to get example metadata before running suite

I'd like to get the metadata for the examples in my suite before running it. I want to parallelize my test suite based off of tags. Anyone know how to get this data during something like RSpec.configure?
I don't see a way to do this while running the suite. You could conceivably create a custom formatter and run the suite with rspec --dry-run --format=MyFormatter, capture the output, extract the metadata and then do what you want with it. Unfortunately it appears the built-in JSON formatter does not output example metadata.
More info on formatters in the RSpec docs.
You can do this by inspecting,
RSpec.current_example.metadata
so for example, to detect if javascript is enabled:
def js_true?
RSpec.current_example.metadata[:js]
end

Sonarqube API single class test coverage

I am trying to retrieve the unit test code coverage for individual classes through the SonarQube API (Sonar version 4.1.2). Everything is working fine, and I can see the metrics okay when I go directly to the sonar dashboard and go to the coverage tab for a class:
93.9% by unit tests Line coverage: 97.9% (285/291) Branch coverage: 85.0% (113/133)
Can anyone tell me the correct call to retrieve this same/similar information through the sonar API interface please? I've already had a look at the documentation at http://docs.sonarqube.org/display/SONAR/Metric+definitions and can get test coverage metrics back at project level but I can't see how to construct a query for individual classes.
I think this is what you are after
[hostname]/api/resources?resource=[com.test]:[module-name]:[fully qualified class]&metrics=coverage,branch_coverage
I have added an example below.
http://sonar-server/api/resources?resource=com.test:module:com.test.service.impl.CheckServiceImpl&metrics=coverage,branch_coverage
I looked at the page you shared and used this also :
http://docs.codehaus.org/pages/viewpage.action?pageId=229743280
api/measures/component_tree is your friend
result = session.get(
SONAR_BASE + "api/measures/component_tree",
params={"baseComponentId": COMPONENT, "metricKeys": "coverage" )
)
gets you coverage down to the file level. You should be able to only get the files with the "leaves" strategy.

How do i know at runtime in Android if it is a test or a live environment?

How do i know at runtime in Android if it is a test environment runned from Eclipse or a signned version installed from the Market? (i need to run some debug code only when testing, because in live i get some ANR reports caught when running this code)
According to http://android-developers.blogspot.co.uk/2010/09/securing-android-lvl-applications.html
boolean isDebuggable = ( 0 != ( getApplcationInfo().flags &= ApplicationInfo.FLAG_DEBUGGABLE ) );
will let you know it if is debuggable, you can then save this to a shared pref or some other method and then check it whenever you want.
You dont need to. You can just log them in Log.d level and then use a tool such as ProGuard to remove such logs
http://proguard.sourceforge.net/
More explanation in this answer Remove all debug logging calls before publishing: are there tools to do this?
EDIT
If that is the case you need to have some sort of boolean value in an external properties file and conditonally write logs.
More info on that here
Variables from properties file in Ant