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

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

Related

Error handling in extensions to visual studio code

Can someone point me to best practices for error handling in a Visual Studio Code extension?
I'm writing an extension in TypeScript that contributes a debugger. I want to log unexpected behavior, sometimes as information to the user explaining that something didn't go right, sometimes to create a trail for debugging, but certainly not to fail silently. Using console.log or console.error shows up in the debug output when I am debugging the extension, but I can't find it when the extension is installed. Do I have to open an output channel specifically for my extension and write everything there? Should I be throwing up showInformationMessage and showErrorMessage windows? Should I just be throwing exceptions and hope that code will do the right thing?
In my extension I use two ways for feedback. One is an output channel for errors produced by an external process that I'm using for the work.
Create the channel in your activation method:
outputChannel = window.createOutputChannel("ANTLR4 Errors");
and push output to it whenever you have something:
} catch (reason) {
outputChannel.appendLine("Cannot parse sentence generation config file:");
outputChannel.appendLine((reason as SyntaxError).message);
outputChannel.show(true);
return;
}
The other one is what you already considered:
if (workspace.getConfiguration("antlr4.generation").mode === "none") {
void window.showErrorMessage("Interpreter data generation is disabled in the preferences (see " +
"'antlr4.generation'). Set this at least to 'internal' to enable debugging.");
return null;
}
which is for messages I create in the extension and that users need to see and take seriously.

How to compile documents and run Jshop2 in Eclipse?

I am a student who begin to study SHOP2 from China.
My teacher told me to run JSHOP2 in Eclipse.Now I can run original zenotravel problem and generate GUI and plans.Likewise, I want to put other domain and problems to SHOP2 and produce plans.
But the problem is that I don't know how to compile them and My teacher only asked me to run the the main function in Internaldomain but it can't succeed.Follow is the original code:
public static void main(String[] args) throws Exception
{
//compile();
// compile(args);
//-- run the planning algorithm
run(args);
}
This code can run zenotravel.Then I put domain and problems named pfile1 and
tdepots respectively into SHOP2 folder.Change the codes to:
{
compile(domaintdepots);
// compile(args);
//-- run the planning algorithm
run(args);
}
It warns "domainpdfiles cannot be resolved to a variable".
Or
//--compile();
compile(args);
//-- run the planning algorithm
//run(args);
It turns out:
"Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 0
at JSHOP2.InternalDomain.compile(InternalDomain.java:748)
at JSHOP2.InternalDomain.main(InternalDomain.java:720)"
720 is main funcition above.And 748 is compile function:
public static void compile(String[] args) throws Exception
{
//-- The number of solution plans to be returned.
int planNo = -1;
//-- Handle the number of solution plans the user wants to be returned.
if (args.length == 2 || args[0].substring(0, 2).equals("-r")) {
if (args[0].equals("-r"))
planNo = 1;
else if (args[0].equals("-ra"))
planNo = Integer.MAX_VALUE;
else try {
planNo = Integer.parseInt(args[0].substring(2));
} catch (NumberFormatException e) {
}
}
Finally,according to the advice of the friend,I put the two pddls into src folder and use “java Jshop2.InternalDomain domaintdepots”in CMD commad but an error appeared:"the main class Interdomain can't be found or loaded".But I have set the class path accurately and the Zenotravel planning can run.So how
and where can I use the command ?
And what is written in the bracket"compile()" in Eclipse?
I am also not familiar with JAVA so it's better if there is concrete instruction.Thanks a lot.
Please describe what are you trying to build, what is it supposed to do, what is the expected end result.
If you do have a valid PDDL domain and problem file, you could try to load them into the online http://editor.planning.domains/ editor using the File > Load menu. Then press the Solve button and confirm which of the file is the domain and which is problem. If the PDDL model is valid (and the underlying solver can handle the requirements), you will get a plan back.
If you are trying to build a software solution that needs a PDDL-based planning engine as one of its component, perhaps you could use one of the available implementations: https://nergmada.github.io/pddl-reference/guide/whatisplanner.html#list-of-planners
If you are trying to build your own planning engine in Java using the Eclipse IDE, you probably need a Java-based PDDL parser. Here is a tutorial, how to use pddl4j for that purpose:
https://github.com/pellierd/pddl4j/wiki/A-tutorial-to-develop-your-own-planner
If you need to use Jshop2 in particular, it looks from their documentation (http://www.cs.umd.edu/projects/shop/description.html) that you need to indeed compile the domain and problem PDDL into Java code using following commands:
java JSHOP2.InternalDomain domainFileName
java JSHOP2.InternalDomain -r problemFileName
Edited on June 19th
Java package names (e.g. JSHOP2) and class names (InternalDomain) are case sensitive, so make sure you type them as per the documentation. That is probably why you are getting the "main class not found error".
It is difficult to say what the lines numbers 748 and 720 exactly correspond to, because in the GitHub repo https://github.com/mas-group/jshop2/blob/master/src/JSHOP2/InternalDomain.java the code is different from yours. Can you indicate in your questions which lines those are exactly?
The make file shows how to execute an out-of-the-box example in the distribution:
cd examples\blocks
java JSHOP2.InternalDomain blocks
java JSHOP2.InternalDomain -r problem300
Does that work for you?

Debugging test cases when they are combination of Robot framework and python selenium

Currently I'm using Eclipse with Nokia/Red plugin which allows me to write robot framework test suites. Support is Python 3.6 and Selenium for it.
My project is called "Automation" and Test suites are in .robot files.
Test suites have test cases which are called "Keywords".
Test Cases
Create New Vehicle
Create new vehicle with next ${registrationno} and ${description}
Navigate to data section
Those "Keywords" are imported from python library and look like:
#keyword("Create new vehicle with next ${registrationno} and ${description}")
def create_new_vehicle_Simple(self,registrationno, description):
headerPage = HeaderPage(TestCaseKeywords.driver)
sideBarPage = headerPage.selectDaten()
basicVehicleCreation = sideBarPage.createNewVehicle()
basicVehicleCreation.setKennzeichen(registrationno)
basicVehicleCreation.setBeschreibung(description)
TestCaseKeywords.carnumber = basicVehicleCreation.save()
The problem is that when I run test cases, in log I only get result of this whole python function, pass or failed. I can't see at which step it failed- is it at first or second step of this function.
Is there any plugin or other solution for this case to be able to see which exact python function pass or fail? (of course, workaround is to use in TC for every function a keyword but that is not what I prefer)
If you need to "step into" a python defined keyword you need to use python debugger together with RED.
This can be done with any python debugger,if you like to have everything in one application, PyDev can be used with RED.
Follow below help document, if you will face any problems leave a comment here.
RED Debug with PyDev
If you are wanting to know which statement in the python-based keyword failed, you simply need to have it throw an appropriate error. Robot won't do this for you, however. From a reporting standpoint, a python based keyword is a black box. You will have to explicitly add logging messages, and return useful errors.
For example, the call to sideBarPage.createNewVehicle() should throw an exception such as "unable to create new vehicle". Likewise, the call to basicVehicleCreation.setKennzeichen(registrationno) should raise an error like "failed to register the vehicle".
If you don't have control over those methods, you can do the error handling from within your keyword:
#keyword("Create new vehicle with next ${registrationno} and ${description}")
def create_new_vehicle_Simple(self,registrationno, description):
headerPage = HeaderPage(TestCaseKeywords.driver)
sideBarPage = headerPage.selectDaten()
try:
basicVehicleCreation = sideBarPage.createNewVehicle()
except:
raise Exception("unable to create new vehicle")
try:
basicVehicleCreation.setKennzeichen(registrationno)
except:
raise exception("unable to register new vehicle")
...

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.

EventLogInstaller Full Setup with Categories?

It appears the MSDN docs are broken concerning creating an Event Log completely along with a definitions file for messages. I am also lost on how to setup Categories (I have custom numbers in the 3000's for messages).
Can anyone point me to a link or show sample code on how to make this right?
You should start (if you haven't done so already) here:
EventLogInstaller Class (System.Diagnostics)
The sample provided there is the foundation for what you want to do. To sum it up, build a public class inheriting from System.Configuration.Install.Installer in an assembly (could be the same DLL where you have the rest of your application, a separate DLL, or an EXE file), decorate it with the RunInstaller attribute, and add your setup code in the constructor:
using System;
using System.Configuration.Install;
using System.Diagnostics;
using System.ComponentModel;
[RunInstaller(true)]
public class MyEventLogInstaller: Installer
{
private EventLogInstaller myEventLogInstaller;
public MyEventLogInstaller()
{
// Create an instance of an EventLogInstaller.
myEventLogInstaller = new EventLogInstaller();
// Set the source name of the event log.
myEventLogInstaller.Source = "NewLogSource";
// Set the event log that the source writes entries to.
myEventLogInstaller.Log = "MyNewLog";
// Add myEventLogInstaller to the Installer collection.
Installers.Add(myEventLogInstaller);
}
}
When you have your assembly compiled, you may use the InstallUtil tool available through the Visual Studio Command Prompt to run the installer code.
Regarding the message definition file (which includes category definitions), the MSDN documentation for EventLogInstaller.MessageResourceFile mentions that you should create an .mc file, compile it, and add it as a resource to your assembly. Digging around, I found an excellent post which should guide you to the end, here:
C# with .NET - Event Logging (Wayback Machine)