Gradle and Specs2 : Specs2-HtmlOutput - scala

Id like to generate HTML-Output as stated in: http://etorreborre.github.io/specs2/guide/org.specs2.guide.Runners.html via the JUnit-Runner
The documentation states that ''you can use the -Dspecs2.commandline property and pass it the html or console values.''
How to do that in a gradle task.
Yes, I know that gradle can produce HTML-Test-Reports but I need the one specs2 can generate.
One problem still remains. I don#t get a navigation menu on the left. Each page has a seperate menu and the results

Just use the systemProperty whitout the -D
test {
systemProperty "specs2.commandline" , "html"
systemProperty "specs2.outDir" , "$buildDir/reports/specs2" // to put the reports in the same dir as other gradle reports
}

Related

Using Eclipse's JDT, how do I identify the classpath for a project?

I am writing a plug-in that will generate unit tests for a Java class that is selected in Eclipse's Project Explorer. This plug-in uses a third-party program called Randoop to generate the tests, so I make this happen using ProcessBuilder:
ProcessBuilder builder = new ProcessBuilder(command);
where the command that is passed to the ProcessBuilder is a list of Strings, something like
["java", "-classpath", "path1;path2;etc", "randoop.main.Main", ...]
Within the plug-in I am trying to generate the classpath for Randoop based on the classpath that Eclipse knows about. Here is some of what I have so far:
IClasspathEntry[] resolvedClasspath = javaProject.getResolvedClasspath(true);
for (IClasspathEntry entry : resolvedClasspath) {
if (entry.getEntryKind() == IClasspathEntry.CPE_SOURCE) {
IPath outputLocation = entry.getOutputLocation();
if (outputLocation != null) {
buf.append(outputLocation.toString());
}
else {
buf.append(entry.getPath().toString());
}
}
else {
buf.append(entry.getPath().toString());
}
buf.append(CLASSPATH_SEP);
}
It isn't quite right. It seems to specify the library jar files okay, but doesn't do so well with identifying the paths to class files corresponding to CPE_SOURCE entries. For example, I see a classpath entry of /myPkgFragRoot/src/main/java instead of myPkgFragRoot/target/classes.
I seem to have a muddled picture of how Eclipse treats classpaths, so I'm looking for some help. Firstly, I'm wondering if my high-level approach is wrong. It seems like I am writing a large amount of code to generate an incorrect classpath. Is there some simpler way of getting a classpath from an IJavaProject than getting the results of getResolvedClasspath and iterating through them and manipulating the individual entries? Secondly, if there isn't a simpler way, how should I be locating the class files produced by building the project?
If the outputLocation is null, you have to use the default output location javaProject.getOutputLocation() instead of entry.getPath().
See Javadoc of IClasspathEntry.getOutputLocation():
Returns:
the full path [...], or null if using default output folder
If in Project > Properties: Java Build Path tab Source the check box Allow output folders for source folders is not checked, IClasspathEntry::getOutputLocation() will always return null.

TestNG - emailable-report issue

I have created java method to send mail and that mail attaching TestNG emailable-report. Mail and report is sending fine to specified email address.
My issue is I am calling sendmail method at last means when all other tests complete but thing is I am always getting previous last report in mail. So is it like TestNG update report after all class execution?
I want to get latest emailable-report in mail rather than previous last emailable-report.. How can I do that?
I want to get latest emailable-report in mail rather than previous
last emailable-report.. How can I do that?
I think..you're sending mail in your #aftersuite.You're getting previous test emailable-report because the test is currently running and only when it finishes reports will be generated.
I will suggest you to use a continuous Integration server like jenkins because it gives sending emails as a post build option or build tool like Maven or ant to run your tests, then have a post test event to email the results.Maven also provides many plugins to automatically send mails after test execution like Postman mail plugin
Another solution : If you are not willing to use a continuous Integration server(jenkins) or maven or ant
TestNG IReporter listener
Create your own CustomReport by implementing your class to IReporter Interface.This interface has only one method to implement generateReport. This method has all the information of a complete test execution in the List and we can generate report using it.
public class CustomReporter implements IReporter{
#Override
public void generateReport(List<XmlSuite> arg0, List<ISuite> arg1,
String outputDirectory) {
// Second parameter of this method ISuite will contain all the suite executed.
for (ISuite iSuite : arg1) {
//Get a map of result of a single suite at a time
Map<String,ISuiteResult> results = iSuite.getResults();
//Get the key of the result map
Set<String> keys = results.keySet();
//Go to each map value one by one
for (String key : keys) {
//The Context object of current result
ITestContext context = results.get(key).getTestContext();
//results of all the test case will be stored in the context object
//Ex: context.getFailedTests(); will give all failed tests and similarly you can get passed and skipped test results make your own html report using the above data
}
}
}
}
Hope this helps you...Kindly get back if you need any further help
For Windows OS, I've created (for TestNG) in #AfterSuite at the end a method to send mail with attachment and batch file with 2 steps. First step launch mvn clean test to execute all test without previous results. Second step launch test without parameter clean and operates on non existing group :)
Batch is in folder with tests.
start /wait cmd /k "mvn clean test && exit" /secondary /minimized
REM to send email with results in file, whitch was composed after test suite (mvn without: clean)
start /wait cmd /k "mvn test -Dgroups=PhantomGroupNonExist && exit" /secondary /minimized

Configuring ScalaDoc task in Gradle to generate aggregated documentation

I have a multi module scala project in Gradle. Everything works great with it, except the ScalaDoc. I would like to generate a single 'uber-scaladoc' with all of the libraries cross-linked. I'm still very new to groovy/gradle, so this is probably a 'me' problem. Any assistance getting this setup would be greatly appreciated.
build.gradle (in the root directory)
// ...
task doScaladoc(type: ScalaDoc) {
subprojects.each { p ->
// do something here? include the project's src/main/scala/*?
// it looks like I would want to call 'include' in here to include each project's
// source directory, but I'm not familiar enough with the Project type to get at
// that info.
//
// http://www.gradle.org/docs/current/dsl/org.gradle.api.tasks.scala.ScalaDoc.html
}
}
The goal here would be able to just run 'gradle doScalaDoc' at the command line and have the aggregate documentation show up.
Thanks in advance.

grizzly logs to stderr, annoying in eclipse

When i run my junit jersey service tests using the grizzly framework in eclipse, the log is directed to stderr. As a result the console window grabs focus, and the log appears red.
I can't figure out the proper configuration steps. From my reading it looks like i need to add the slf4j.jar to my pom.xml and add a logging properties file somewhere? But i'm unsure which slf4j jars to add (there are many) or where to place the logging properties file.
Or, frankly, if this is the right approach in general.
p.s. also i am aware i can turn off the "show console when standard error changes" feature in eclipse, but i'd rather not paint over the problem. :)
It doesn't look to me like Grizzly used slf4j, but rather the "standard" java.util.logging framework. If that's the case, you can read about configuring it here: http://docs.oracle.com/javase/6/docs/technotes/guides/logging/overview.html#1.8
With Eric's help above I created this class:
package org.trebor.www;
import java.util.logging.ConsoleHandler;
import java.util.logging.Handler;
import java.util.logging.Logger;
public class LoggerTrap
{
public LoggerTrap()
{
Handler handler =
new ConsoleHandler()
{
{
setOutputStream(System.out);
}
};
Logger.getLogger("").addHandler(handler);
}
}
and added this jvm arg
-Djava.util.logging.config.class=org.trebor.www.LoggerTrap
and all java.logging goes to STDOUT. In the process I've learned that I don't much like java.logging.

How do I verify that an NUnit Addin has been loaded?

From what I can tell, the assembly containing the addin must be located in C:\Program Files (x86)\NUnit 2.5.7\bin\net-2.0\addins. I think my assembly is being loaded because I have to close NUnit-gui before I can replace the assembly in the addins directory. The problem, however, is that I don't see any of the effects of the addin (None of the event handlers are being called)
So how do I verify that my addin has been loaded? I'd love to step through with the debugger but I'd be perfectly happy with print line debugging. When I tried doing a File.WriteAllText() the addin failed to load but gave no reason. Also, how do I debug the loading process?
The NUnit docs are helpful, but they're bare bones at best when it comes to extensibility and there isn't any intellisense available for classes in NUnit.Core.
You should use some tracing library like this one which you can download here.
Now you can decorate your relevant methods with using statements like this:
using ApiChange.Infrastructure;
class MyAddin
{
static TypeHashes myType = new TypeHashes(typeof(MyAddin);
void RelevantMethod()
{
using (Tracer t = new Tracer(myType, "RelevantMethod"))
{
....
if(bLoaded == false)
t.Error("Could not load adding because of {0}", reason);
}
}
}
Then you can enable tracing via the environment variable _TRACE
set _Trace=debugoutput
DebugOutput can be viewed with the SysInternals tool DbgView (no attach simply start it and watch the traces).
Or you trace to a file
set _Trace=file
The trace file is located where the executable is e.g. Nunit.exe.txt. If you set _TRACE to some random string it will trace the help to console and OutputDebugString to give you help.
Why this trace library? It is actually the ONLY one which is able to trace any exception when your method is left. This does work when the method contains using statements for tracing like the one above. If it is actually your fault that NUnit does choose to ignore your plugin you can find out now.
The output will look like this:
* ApiChange.IntegrationTests.Diagnostics.TracingTests.Demo_Show_Leaving_Trace_With_Exception
18:57:46.665 03064/05180 <{{ > ApiChange.IntegrationTests.Diagnostics.TracingTests.SomeMethod
18:57:46.668 03064/05180 <{{ > ApiChange.IntegrationTests.Diagnostics.TracingTests.SomeOtherMethod
18:57:46.670 03064/05180 < }}< ApiChange.IntegrationTests.Diagnostics.TracingTests.SomeOtherMethod Exception thrown: System.NotImplementedException: Hi this a fault
at ApiChange.IntegrationTests.Diagnostics.TracingTests.FaultyMethod()
at ApiChange.IntegrationTests.Diagnostics.TracingTests.SomeOtherMethod()
at ApiChange.IntegrationTests.Diagnostics.TracingTests.SomeMethod()
at ApiChange.IntegrationTests.Diagnostics.TracingTests.Demo_Show_Leaving_Trace_With_Exception()
18:57:46.670 03064/05180 < }}< ApiChange.IntegrationTests.Diagnostics.TracingTests.SomeOtherMethod Duration 2ms
18:57:46.689 03064/05180 < }}< ApiChange.IntegrationTests.Diagnostics.TracingTests.SomeMethod Duration 24ms
That should make it easy to find out why your Addin was not used at all. And you do not need a debugger ;-).
Yours,
Alois Kraus