JUnit5 Console Launcher not finding tests - junit5

I've seen a number of posts on this, but none of the solutions seem to work for me.
The problem is that the JUnit5 console launcher cannot seem to find my tests, regardless of syntax that I try. I've tried scanning for them with --scan-classpath and specifying the class directly with -c, including the package specifier, which generates a NoClassDefFound.
With --scan-classpath the console launcher runs successfully, but doesn't include any unit test executions - doesn't find the test classes for some reason.
The tree looks like this:
junit-5-jars (the console standalone jar is in here)
src
mypackage
MyClass.java
MyClass.class
test
mypackage
MyClassShould.java
MyClassShould.class
From the root of that, the first and most basic command I tried:
java -jar junit5-jars/junit-platform-console-standalone-1.7.0-all.jar --class-path=test --class-path=src --scan-classpath
All variations I've tried give me:
Test run finished after 27 ms
[ 2 containers found ]
[ 0 containers skipped ]
[ 2 containers started ]
[ 0 containers aborted ]
[ 2 containers successful ]
[ 0 containers failed ]
[ 0 tests found ]
[ 0 tests skipped ]
[ 0 tests started ]
[ 0 tests aborted ]
[ 0 tests successful ]
[ 0 tests failed ]
This is on a Mac from bash. In a project with all class files at the root of where I'm running the command, I can run tests with the console launcher successfully. But if class files are in subdirectories like this, no go. Anyone have ideas? (Note - see answer below, subdirectories were not the issue - the "Should" in the test class name was).

I think I've discovered the source of this problem - it was the "Should" in the test class name, which JUnit5 ConsoleLauncher does not include to be scanned by default.
This works:
java -jar junit5-jars/junit-platform-console-standalone-1.7.0-all.jar --class-path=test:src --include-classname=.* --scan-classpath
The include classname option takes a regex, but in my case I just let it scan all the files on the classpath for tests, and it finds them as it should.
Would be helpful if the --scan-classpath description in their docs referenced the include-classname option and/or their default scanning inclusions. Easy to miss that argument in that wall of options.

Related

Why are some Protractor tests skipped?

When I launch protractor conf.js and this file needs to launch multiple spec files (like below), some of them are (randomly?) skipped. It works quite well when I run each spec separately.
specs: [
'tests/test-1-*.js',
'tests/test-2-*.js',
'tests/test-3-*.js'
],
I've found a workaround, but now I would like to know the root cause... Any idea?

Problem with dokka CLI - "Exiting Generation: Nothing to document"

I'm trying to generate documentation for my kotlin code. Some of my classes and functions have KDOC comments.
I tried to run dokka from the CLI like this:
java -jar dokka-cli-1.4.20.jar
And the result was:
WARN: Dokka 1.4.* is an alpha project PROGRESS: Initializing plugins
Loaded plugins: [] Loaded: [
] Suppressed: [
] PROGRESS: Validity check PROGRESS: Creating documentation models
PROGRESS: Exiting Generation: Nothing to document PROGRESS:
=== TIME MEASUREMENT ===
Initializing plugins: 26
Validity check: 32
Creating documentation models: 28
Exiting Generation: Nothing to document: 1
I have tried to execute this:
in the project's folder.
in the src folder
in the first src sub-folder that has .kt files
The result was similar for all runs.
Any ideias on how to solve this? Thanks.

How to run java agent on Corda node by configuring jvm args in gradle build?

I am trying to run a JavaAgent that monitors the code execution on one or multiple Corda nodes so I can track coverage of my functional tests when they are running.
The Corda docs say you can add JVM args by adding this to my node spec:
custom = {
jvmArgs: [ "-javaAgent:/Path/To/Agent/jacoco-agent.jar=config-file=/Path/To/Agent/jacoco-agent.config", "-Xmx1G", "-XX:+UseG1GC" ]
}
It seems that I have to add this to each nodes config file but is there a way to add this to all nodes through the build.gradle for example so the agent starts when the node start.
you can edit the node.conf of the generated nodes from the node or nodeDefaults section of the deployNodes task (or any task of type net.corda.plugins.Cordform) in the build.gradle, so you can simply use
node {
extraConfig = ['custom.jvmArgs': ["-Xmx1G", "-XX:+UseG1GC"]]
}
note that in Groovy, both lists and dictionaries use square bracket syntax
e.g.
["key" : "value", "key2" : true, "key3" : 42]

compile_time_purge_matching doesn't work during testing

The following config.exs
config :logger,
compile_time_purge_matching: [
# [application: :foo],
[module: SomeModule, level_lower_than: :error]
]
Above code works when running from shell but not when doing mix test
The config.exs is clearly parsed and i can't find that the configuration is overridden anywhere.

Behat 2.4 upgrade issues, or Unrecognized options "extensions" under "behat" - error when attempting to activate sahi extension via behat.yml

Fairly new to this Behat stuff, and I've run into a roadblock I can't seem to get around. I've been staring at the docs, googling like it's my job, and doing my best to refrain from tossing my computer off the fire escape.
I'm working with a fairly complex project, and I'm not the one who set it up. So I'm a little lost in some areas.
Currently, I'm trying to use the Sahi driver, because selenium isn't cutting it for some dynamic forms I need to test. I can run the tests fine with the default selenium driver, but the tests fail because it doesn't adequately trigger JavaScript events on form input. Specifically, it'll work with the workarounds covered in that link, but only if I have the browser in focus. Which means it fails when the tests are run in sauce or via jenkins with xvfb.
I'm explaining all this only because this is my larger issue, which I'm attempting to address by using the Sahi driver. Which brings me to:
[Symfony\Component\Config\Definition\Exception\InvalidConfigurationException]
Unrecognized options "extensions" under "behat"
That's what I get when I try to activate the Sahi driver for a particular profile in my bahat.yml the way the documentation says to.
Here's the default profile and the profile I'm currently working with in my behat.yml (slightly modifies for public consumption):
default:
paths:
features: 'features'
bootstrap: '%behat.paths.features%/bootstrap'
sahi:
extensions:
Behat\MinkExtension\Extension:
sahi: ~
context:
class: 'FeatureContext'
parameters:
environment: 'staging'
mink: 'sahi'
Fwiw, the tests are on a vm, which I ssh -X into, then run the test using
$ behat --tags #test_name_tag --profile=sahi
When I'm using the default selenium driver and the #javascript tag, the browser pops up and the tests run and pass (assuming I keep the browser in focus, of course).
I installed the additional drivers using composer:
{
"require": {
"behat/behat": "2.4.*#stable",
"behat/mink": "1.4#stable",
"behat/mink-extension": "*",
"behat/mink-selenium2-driver": "*",
"behat/mink-sahi-driver": "*"
}
}
I've added use Behat\Mink\Driver\SahiDriver; to my MinkContext.php, EnvironmentContext.php and FeatureContext.php, though I'm guessing that's probably either overkill or not necessary. It doesn't seem to be making a difference at this point, though. I get the same error with or without it.
I also added a sahi.php which lives in features/bootstrap/mink:
<?php
return
array(
'default_session' => 'sahi',
'sahi' => array(
'capabilities' => array(
'browserName' => 'firefox',
'browserVersion' => 7,
),
),
);
I thought maybe adding a directory in features/bootstrap called exensions might help for some reason. Even stuck a file in there called sahi.php. That didn't help much.
I think that covers everything. Thanks in advance for any help, and if this is covered elsewhere, please direct me to it, because I've spent countless hours looking and haven't found anything that helps me.
Update:
I uninstalled the old versions of behat, mink and gherkin, and installed 2.4, et al as per this https://lestbddphp.wordpress.com/2012/08/31/behatcomposer/
I've been making my way through "Migrating from Behat 2.3 to 2.4" in the docs. (Sorry, SO won't let me post any more links, but it's in the official Behat docs.)
My composer.json:
{
"require": {
"behat/behat": "2.4.*#stable",
"behat/mink": "1.4#stable",
"behat/mink-goutte-driver": "*",
"behat/symfony2-extension": "*",
"symfony/class-loader": "2.1.*",
"symfony/form": "2.1.*",
"symfony/validator": "2.1.*",
"behat/mink-selenium-driver": "*",
"behat/mink-selenium2-driver": "*",
"behat/mink-extension": "*",
"behat/mink-sahi-driver": "*"
},
"minimum-stability": "dev",
"config": {
"bin-dir": "bin/"
}
}
I moved my behat.yml file to the root of the project, as directed. I updated my default profile to:
default:
paths:
features: 'features'
bootstrap: '%behat.paths.features%/bootstrap'
extensions:
Behat\Symfony2Extension\Extension:
mink_driver: true
kernel:
env: test
debug: true
Behat\MinkExtension\Extension:
default_session: symfony2
sahi: ~
though I'm not entirely sure that's what I need. Just going by the example given in the docs.
I updated my vendor/autoload.php by replacing the require_once with require:
<?php
// autoload.php generated by Composer
require __DIR__ . '/composer' . '/autoload_real.php';
return ComposerAutoloaderInit::getLoader();
but I'm a little confused by this, because that file is different from the example code in the docs. If I were to add the line in the docs here, instead of what was already there, then it would just be loading itself. (I tried. It barfed.) Am I completely dense, or is the wording here confusing/misleading? Did I do this correctly?
As I mentioned before, I have 3 context files in features/bootstrap:
FeatureContext.php
EnvironmentContext.php
MinkContext.php
When running the tests via cli, I pass it a --profile, and then it uses the appropriate profile in behat.yml. In almost all of the profiles, FeatureContext is used.
context:
class: 'FeatureContext'
FeatureContext then gets EnvironmentContext and MinkContext, from what I can tell. So, theoretically, everything should be working there.
Only it's not.
$ bin/behat --profile=sahi
[ReflectionException]
Class AppKernel does not exist
Before I added all the Symfony stuff, I was getting this:
Warning: require(Behat\Symfony2Extension\Extension): failed to open stream: No such file or directory in /path/to/project/vendor/behat/behat/src/Behat/Behat/Extension/ExtensionManager.php on line 112
Fatal error: require(): Failed opening required 'Behat\Symfony2Extension\Extension' (include_path='/usr/share/pear:/usr/share/php:/usr/share/git core/templates/hooks:.') in /path/to/project/vendor/behat/behat/src/Behat/Behat/Extension/ExtensionManager.php on line 112
Which is why I added the Symfony stuff via composer.
Also possibly of note: when I forgot to pass it a --profile, before installing the Symfony stuff via composer, I got this:
Notice: Undefined index: environment in /home/lbaron/development/BeHat-Functional/features/bootstrap/FeatureContext.php on line 43
Warning: include(/path/to/project/features/bootstrap/environment/.php): failed to open stream: No such file or directory in /path/to/project/features/bootstrap/FeatureContext.php on line 44
Warning: include(): Failed opening '/path/to/project/features/bootstrap/environment/.php' for inclusion (include_path='/usr/share/pear:/usr/share/php:/usr/share/git-core/templates/hooks:.') in /path/to/project/features/bootstrap/FeatureContext.php on line 44
Catchable fatal error: Argument 1 passed to EnvironmentContext::__construct() must be an array, boolean given, called in /path/to/project/features/bootstrap/FeatureContext.php on line 44 and defined in /path/to/project/features/bootstrap/EnvironmentContext.php on line 27
Which I guess is to be expected.
So I'm at a loss now. Ideas?
I'm going to keep banging on it to see if I can figure it out, but any ideas/input would be greatly appreciated.
Update again:
Removing the extensions section from yml gives me this:
Catchable fatal error: Argument 2 passed to Symfony\Component\BrowserKit\Client::__construct() must be an instance of Symfony\Component\BrowserKit\History, array given, called in /usr/share/pear/mink/src/Behat/Mink/Behat/Context/MinkContext.php on line 163 and defined in /home/lbaron/development/BeHat-Functional/vendor/symfony/browser-kit/Symfony/Component/BrowserKit/Client.php on line 52
Current state of behat.yml:
default:
paths:
features: 'features'
bootstrap: '%behat.paths.features%/bootstrap'
formatter:
parameters:
language: 'en'
extensions:
Behat\MinkExtension\Extension:
sahi: ~
goutte: ~
You are running a version of behat which is older that 2.4 (the current version). I can tell because the command you use is "behat" instead of "bin/behat". Older versions had a different architecture and did not use extensions. The documentation on the behat.org website is all for the new 2.4 version and, as far as I know, does not have the documentation for older versions available anymore. You should upgrade your behat version to 2.4, there is a guide on how to do this here