sbt testOnly not working - unit-testing

I'm trying to run a single test class in a Java Play project but fails misserably.
If I try to run
testOnly my.app.TheClassTest
from within sbt (as described in JavaTest and sbt test) I get this result:
[info] Passed: Total 0, Failed 0, Errors 0, Passed 0
[info] No tests to run for test:testOnly
My only suspicion is that the message "No tests to run for test:testOnly" does not include the name of the class I try to test.
If I try to run it from command line
sbt testOnly "my.app.TheClassTest"
It runs all the tests and then I get the following error:
[error] Expected ID character
[error] Not a valid command: net (similar: set, new, inspect)
[error] Expected project ID
[error] Expected configuration
[error] Expected ':' (if selecting a configuration)
[error] Expected key
[error] Not a valid key: my (similar: test, name, assets)
[error] my.app.TheClassTest
I've tried all kinds of variations such as testOnly TheClassTest, test-only my.app.TheClassTest, test:testOnly etc. with only minor variations in result. Using testOnly within sbt I can write whatever I feel like and still always get the same response.
Running all tests work fine.
Is there at least a way to get a more

From sbt you can try to get the autocompletion for the command:
sbt:my-project> testOnly <tab>
When running from command line (so outside the sbt prompt), for example in continuous integration, or other scripts etc., then you take the command in quotes including the argument, like this:
sbt "testOnly my.package.TheClassTest"
Otherwise testOnly does not seem to receive the argument.

From sbt you can try to get the autocompletion for the command:
sbt:my-project> testOnly <tab>
It should display the lists of tests classes that are available. This may not work with the oldest versions of sbt.
If you see no classes, try to run test:compile before to compile your test classes.

For sbt 1.5.2, this worked:
sbt "project dbm; testOnly my.package.TestClass"

Related

Module test path not found

I'm trying to configure a GitHub action:
My action contains the job for running the unit test by collecting code coverage. As I see in the log:
Test Run Successful.
Total tests: 336
Passed: 336
Total time: 14.0930 Seconds
Calculating coverage result...
Generating report 'TestResults/coverage.netcoreapp2.1.info'
Nonetheless, after these lines log contains an error message:
/home/runner/.nuget/packages/coverlet.msbuild/2.9.0/build/coverlet.msbuild.targets(31,5): error : Module test path not found [/home/runner/work/ObservableComputations/ObservableComputations/src/ObservableComputations.Test/ObservableComputations.Test.csproj]
The job is failed.
I tried to run
dotnet test --no-build --filter Name~Casting --verbosity normal /p:CollectCoverage=true /p:CoverletOutput=TestResults/ /p:CoverletOutputFormat=lcov
at my local machine (MS Windows) and didn't get this error.
Any help is greatly appreciated.
The reason was in -no-build parameter for dotnet test. It seems coverage collecting requires dotnet test to build itself.

Getting error while building project "com.bea.util.jam.internal.javadoc.JavadocClassloadingException:"

I am getting error while trying to build a java project in TeamCity. The same project builds and excecutes well on my local. I recently pushed changes to this project on GitLab. This is my first time working with GitLab and TeamCity together. Other projects have no issues during build. I am unable to understand what is causing this error:
[15:58:54][Step 1/1] compile.earCommons (4s)
[15:58:54][compile.earCommons] echo
[15:58:54][compile.earCommons] echo
[15:58:54][compile.earCommons] wlcompile (4s)
[15:58:59][wlcompile]
com.bea.util.jam.internal.javadoc.JavadocClassloadingException: An error
has occurred while invoking javadoc to inspect your source
files. This may be due to the fact that $JAVA_HOME/lib/tools.jar does
not seem to be in your system classloader. One common case in which
this happens is when using the 'ant' tool, which uses a special
context classloader to load classes from tools.jar.
This situation elicits what is believed to a javadoc bug in the initial
release of JDK 1.6. Javadoc attempts to use its own context classloader
tools.jar but ignores one that may have already been set, which leads
to some classes being loaded into two different classloaders. The
telltale sign of this problem is a javadoc error message saying that
'languageVersion() must return LanguageVersion - you might see this
message in your process' output.
This will hopefully be fixed in a later release of JDK 1.6; if a new
version of 1.6 has become available, you might be able to solve this
by simply upgrading to the latest JDK.
Alternatively, you can work around it by simply including
$JAVA_HOME/lib/tools.jar in the java -classpath
parameter. If you are running ant, you will need to modify the standard
ant script to include tools.jar in the -classpath.
[15:58:59][Step 1/1] Process exited with code 1
[15:58:59][Step 1/1] Ant output
[15:59:10][Step 1/1] Process exited with code 1 (Step: Ant)
[15:58:59][Step 1/1] Step Ant failed
****Update****
Build Step: Ant
Step 1:
Runner type: Ant (Runner for Ant build.xml files)
Execute: If all previous steps finished successfully
build.xml file: \ant\build.xml
Working directory: same as checkout directory
Targets: none specified
Ant home path: C:\apache-ant-1.7.0
Additional Ant command line parameters: -lib c:\WebLogic\12.1.2\wlserver\server\lib\javaee.jar;c:\WebLogic\12.1.2\wlserver\server\lib\weblogic.jar;c:\WebLogic\12.1.2\wlserver\server\lib\webservices.jar
JDK home path: c:\Program Files\Java\jdk1.7.0_80
JVM command line parameters: not specified
Reduce test failure feedback time: OFF
Java code coverage: disabled
Docker Settings
Docker Image: unset
I'll appreciate any help in this regard.
I found there was character encoding issue with one of the files that prevented compiler from loading the java classes. Once that was fixed, the build worked fine.

Codenvy C++ Hello World program won't build?

I am starting to try and use an online IDE, so I started with Codenvy. I created a workspace and a project and I typed in the following code for a Hello World program just to test the IDE.
#include <iostream>
int main () {
std::cout << "Hello World!" << std::endl;
return 0;
}
It didn't build correctly. This is what the build log says:
[INFO] Scanning for projects...
[ERROR] [ERROR] Some problems were encountered while processing the POMs:
[FATAL] Non-readable POM /projects/Testing-CPP/pom.xml: /projects/Testing-CPP/pom.xml (No such file or directory) #
#
[ERROR] The build could not read 1 project -> [Help 1]
[ERROR]
[ERROR] The project (/projects/Testing-CPP/pom.xml) has 1 error
[ERROR] Non-readable POM /projects/Testing-CPP/pom.xml: /projects/Testing-CPP/pom.xml (No such file or directory)
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/ProjectBuildingException
Can anyone point me in the right direction to getting the IDE to build and run my code?
It looks like you have your project setup as Java/Maven type so it's looking for a pom.xml and probably trying to run mvn clean install.
Project typing is one of the powerful paradigms in Codenvy and Eclipse Che - it allows projects with specific "types" to assume certain behaviors and auto-setup certain things in the environment. So a Java Maven typed app knows that maven must be installed and can auto-add a build command for mvn clean install since that will work with nearly every Maven app.
Try starting with a clean workspace based on the Codenvy C++ stack and the console-cpp-simple sample application. When you get in the workspace you'll see you have a build command that executes a gcc command.
Then you can import your project from inside the IDE by going to Workspace > Import Project. You can then copy the build command from the sample app and (if necessary) modify it for your app. Once your app compiles you can just deleted the hello world C sample app.
You can also select the project you have now and choose Project > Configuration but that won't necessarily add the right compile command for you.
Your code is all right, so that means there is something wrong with the way you have set up your project, as the error message specifies:
The build could not read 1 project -> [Help 1]
[ERROR]
[ERROR] The project (/projects/Testing-CPP/pom.xml) has 1 error
[ERROR] Non-readable POM /projects/Testing-CPP/pom.xml: /projects/Testing-CPP/pom.xml (No such file or directory)
The following link provides a tutorial on how to make your first Hello World program on CodeEnvy:
Running C++ Hello World in the Cloud - Blog
Go over the insuctions provided; if there is anything they did that you didn't, then that is probably where you went wrong.
Good luck!

How to run nosetests in jenkins

I have a project which has two folders on same level
/home/ishan/my_repo/jenkins_test/business_logic
/home/ishan/my_repo/jenkins_test/test_cases
test_cases has two files test_fib and test_fact
when I run nosetests --exe at /home/ishan/my_repo/jenkins_test/ it runs correctly showing
....
----------------------------------------------------------------------
Ran 4 tests in 0.036s
OK
I am trying to run these test cases so, I created following script at /home/ishan/my_repo
#!/bin/bash
source /home/ishan/venv/bin/activate
nosetests --exe /home/ishan/sf_shared/my_repo/jenkin_test/
deactivate
When I run it using
source /home/ishan/my_repo/test_runner.sh it shows correct output.
So, I tried to put it in jenksins build step. So, I added the same line
source /home/ishan/my_repo/test_runner.sh in command section of Execute Shell in jenkins.
Now, when I trigger the build using build now it fails saying
Started by user anonymous
Building in workspace /var/lib/jenkins/workspace/jenkins_test
[jenkins_test] $ /bin/sh -xe /tmp/hudson5020664150857393715.sh
+ source /home/ishan/sf_shared/test_runner.sh
/tmp/hudson5020664150857393715.sh: 2: /tmp/hudson5020664150857393715.sh: source: not found
Build step 'Execute shell' marked build as failure
Finished: FAILURE
I think it doesn't even execute any test cases. It fails long before.
Can you suggest what am I doing wrong?
Maybe this will works:
/home/ishan/venv/bin/nosetests --exe /home/ishan/sf_shared/my_repo/jenkin_test/
Resolved it, issue was with the following line
source /home/ishan/venv/bin/activate
I replaced it source with standard . then it worked. So, my line became
. /home/ishan/venv/bin/activate

Getting extended information on Django unittest framework

I am using Django unit test framework for testing my application.
When ever I am executing all the test cases I am getting very brief information about the test cases that ran successfully.
----------------------------------------------------------------------
Ran 252 tests in 8.221s
OK
This is the very little information. I wanted to have some more information about each test case,
e.g.
Time taken by each test case to execute.
successful completion of each test module.
etc etc.
Do we have any debug(or any other parameter) parameter that can enable this extended information about the test cases that got executed?
NOTE:- using verbosity parameter does not satisfy my needs
Each django command has a --help option, if you type:
python manage.py test --help you will see all the available options for the command test:
Options:
-v VERBOSITY, --verbosity=VERBOSITY
Verbosity level; 0=minimal output, 1=normal output,
2=verbose output, 3=very verbose output
--settings=SETTINGS The Python path to a settings module, e.g.
"myproject.settings.main". If this isn't provided, the
DJANGO_SETTINGS_MODULE environment variable will be
used.
--pythonpath=PYTHONPATH
A directory to add to the Python path, e.g.
"/home/djangoprojects/myproject".
--traceback Raise on exception
--noinput Tells Django to NOT prompt the user for input of any
kind.
--failfast Tells Django to stop running the test suite after
first failed test.
--testrunner=TESTRUNNER
Tells Django to use specified test runner class
instead of the one specified by the TEST_RUNNER
setting.
--liveserver=LIVESERVER
Overrides the default address where the live server
(used with LiveServerTestCase) is expected to run
from. The default value is localhost:8081.
-t TOP_LEVEL, --top-level-directory=TOP_LEVEL
Top level of project for unittest discovery.
-p PATTERN, --pattern=PATTERN
The test matching pattern. Defaults to test*.py.
--version show program's version number and exit
-h, --help show this help message and exit
As you can see you can set a verbosity level by adding: -v [level]
Try for example with: python manage.py test -v 3
If you want the time for each test, plus some extra info, check out django-juno-testrunner as one option. We wanted more info out of our test runs, so we built it in.
Note that it's Django 1.6+ only at the moment