Display my tests using Eclipse JUnit plugin?

2019-05-03 23:16发布

问题:

I have written a test framework for a company-specific language. This test framework is able to output JUnit-like XML.

As an example, I can save it to file and open it using Eclipse JUnit view, or disp^lay it in my Hudson server. I want now to have it directly integrated in my Eclipse, in order for these tests to be run on Eclipse "save" action, and for their results to be displayed in a JUnit view.

What is the best way to do that ?

  • Save them to file and open that file in Eclipse (and if so, how to do it ?)
  • Directly populate a JUnit view with content of XML ? (and if so, how to do it ?)
  • Create my own view (which I would like to do, as I'm a complete beginner in SWT)

回答1:

I haven't tried this myself, but I imagine that with a little bit of trickery, it would be possible to automatically open a properly formatted file in the JUNit view.

I think a call to org.eclipse.ui.ide.IDE.openEditor(IWorkbenchPage, URI, String, boolean) should work. This is because JUnit-formatted xml files are set to be opened with the JUnit view.

Before you get to this point, you need to create an Eclipse plugin. This will be a simple plugin that will have one class that will listen for the completion of runs for your testing framework, and another class that will know where to find the resulting xml files and will call openEditor on it.



回答2:

In my opinion the best way is create a simple Eclipse plugin, that shows your view. Eclipse has a pretty good API to do that and there is a lot of documentation. From my experience implementing Eclipse plugins, you don't need to be a good GUI designer since most controls are written and you can reuse it.

If you decide to take this way, here are some resources to start:

  • Creating a minimal Eclipse plugin
  • Implementing a simple view with context menu.
  • Understanding Eclipse viewers

Hope it helps.