how to hide "skipped tests" on phpunit - phpunit

With PHPUnit you can skip tests by calling self::markTestSkipped('...'). I mainly do this when optional extensions aren't available. But is there a way to exclude these from PHPUnits output?

I don't think you can "hide" or not show those messages or ignore that test by using markTestSkipped, but you can use #require to ignore tests that do not meet a condition (not any).
For example, using #require extension redis >= 2.2.0 will literally skip that test if you don't have redis >= 2.2.0.
I still think it is not exactly what you want, but may be more helpful

Related

How to include the application's version number in a Scala.js program?

Basically, I'm curious if something like SBT including the version number in a program is possible for Scala.js. The proposed solution doesn't work in scala.js, apparently due the the absence of the getPackage method:
[error] Referring to non-existent method java.lang.Class.getPackage()java.lang.Package
Use sbt-buildinfo for that. The Usage section of the readme contains everything you need.

Play Framework will not recognize Java Options (JVM args) passed in Build.scala

All,
I'm trying to get Play Framework to recognize JVM arguments in all modes (test, run start) by setting them in Build.scala.
Unfortunately, Play ignores everything I've thrown at it.
I've set Keys.javaOptions and Keys.fork, but it SBT flat out ignores the fork command. I also tried going at this by replacing Build.scala with build.sbt, but that doesn't seem to work either.
I realize you can set JAVA_OPTS or PLAY_OPTS in your environment, but this is really lousy way of doing things. One should be able to configure this at the application level and play should be smart enough to either spawn a new process or re-launch itself with the appropriate configuration.
Anyone able to get this to work? If so, can you provide a complete, working solution?
The Play Framework SBT keys override javaOptions you pass, and therefore it will not work.
The way to do it ,according to the documentation, is to pass those arguments at the start command.
The syntax changes a bit from version to version, but at 2.2.x it is:
$ /path/to/bin/<project-name> -J-Xms128M -J-Xmx512m -J-server

cppcheck reporting false positives

I am running cppcheck on my project and am getting reports of unused Functions that ARE definitely used (project wont compile if I remove them).
Are there any known reasons why this might happen ? or how I can stop the false reports
Thanks
In case this error is still present in the latest version of cppcheck, could you please create a minimal example that demonstrates the issue. Having such a test case, the cppcheck developers can fix the issue. I also recommend that you report such issues to cppcheck bugtracker here.
One reason is that you did not configure as expected Cppcheck, you have to specify the include paths and defines, you can also use CppDepend which integrate now cppcheck and did all the configuration staf from the projects you analyse, and also report all methods not used.

Test suites info in PHPUnit bootstrap file

I am running test using a phpunit.xml.dist file. This file defines several test suites and specifies a bootstrap.php. In this bootstrap.php I am currently loading all dependencies for all tests.
A small subset of the tests is dependent on some third party library, which is optional. These tests are all part of a particular test suite. So I only want to load this library in the bootstrapping file when that particular test suite is specified.
How can I determine if this test suite was specified? This then ensures that most tests can be run when the library is not loaded, and that one can easily verify the code and tests that should not depend on the library indeed do not need it.
I currently have the following. Is there something better?
if ( !in_array( '--testsuite=WikibaseDatabaseStandalone', $GLOBALS['argv'] ) ) {
require_once( __DIR__ . '/evilMediaWikiBootstrap.php' );
}
The feature request on the PHPUnit bugtracker for a test suite specific bootstrap is here: https://github.com/sebastianbergmann/phpunit/issues/733
For now there are two options: One is yours which is fine but feels really hackish and doesn't work out well if you run "all the tests" if you have specific bootstrap for every one of them.
My suggestion would be to write a test listener and hook into "startTestSuite" and "endTestSuite". This is a nice maintained and BC compatible way to execute code only when the test suite is actually started and you can also clean up afterwards.
See http://phpunit.de/manual/3.7/en/extending-phpunit.html#extending-phpunit.PHPUnit_Framework_TestListener and http://phpunit.de/manual/3.7/en/appendixes.configuration.html#appendixes.configuration.test-listeners for how to include the test listener.
One of the usual way to handle this is to check if a required dependency is installed, and if not, run
$this->markTestAsSkipped('lib not installed');
That skipping can also happen in the setUp() phase of a test.
Finally, you can add #group annotations to the test-class and/or test functions to give some choice to whether or not the test is run from the command line (with the --group [names...] parameter).
Finally, an option that has also been used in the ZendFramework is to only add the TestSuite that runs a subset within a larger set of a testsuite - in code. There is an example of being able to
a) turn off as will,
b) turn off if the extension is not loaded, or
c) run the tests, for the use of (for example)
caching with APC

Setting system properties with "sbt run"

I'm using a pretty recent version of SBT (seems to be hard to figure out what the version is). I want to pass system properties to my application with sbt run as follows:
sbt -Dmyprop=x run
How could I do that?
SBT's runner doesn't normally create new processes, so you also have to tell it to do this if you want to set the arguments that are passed. You can add something like this to your build settings:
fork := true
javaOptions := Seq("-Dmx=1024M")
There's more detail on forking processes in the SBT documentation.
I found the best way to be adding this to build.sbt:
// important to use ~= so that any other initializations aren't dropped
// the _ discards the meaningless () value previously assigned to 'initialize'
initialize ~= { _ =>
System.setProperty( "config.file", "debug.conf" )
}
Related: When doing this to change the Typesafe Configuration that gets loaded (my use case), one needs to also manually include the default config. For this, the Typesafe Configuration's suggested include "application" wasn't enough but include classpath("application.conf") worked. Thought to mention since some others may well be wanting to override system properties for precisely the same reason.
Source: discussion on the sbt mailing list
Thanks for the pointer, this actually helped me solve a somewhat related problem with Scala Tests.
It turned out that sbt does fork the tests when there are sub-projects (see my code) and some of the tests fail to pick up the system property.
So in sbt -Dsomething="some value" test, some of the tests would fail when failing to find something in the system properties (that happened to be my DB URI, so it kinda mattered!)
This was driving me nuts, so I thought I'd post it here for future reference for others (as #akauppi correctly noted, chances are high that "others" may well be me in a few weeks!).
The fix was to add the following to build.st:
fork in Test := false
I think the best is to use the JAVA_OPTS environment variable:
#update the java options (maybe to keep previous options)
export JAVA_OPTS="${JAVA_OPTS} -Dmyprop=x"
#now run without any extra option
sbt run
You can pass system properties at the end of the sbt command:
sbt run -Dmyprop=x
If you have to pass program parameters into a stage, just pass system properties after the quotes again:
sbt "runMain com.example.MyClass -p param-value" -Dmyprop=x

Resources