How do can i display all test cases of TestNG upfront to choose some for execution - test explorer? - eclipse

Is there an IDE / plugin for an IDE / other way to displays all test cases of an project upfront? And then select and execute them from that view. A test explorer.
I want to get an overview of all tests, the wohle suite, without executing all once. Like a dry run but, executable afterwards with no extra effort.
At best with all cases from data providers included to run specific cases.
I have yet tried Eclipse and Intellij with their plugins.
I'm a software tester developing automated system tests / integration tests. As this tests are running half an hour and more, i don't want to wait for their execution to end to get an overview.
Language is groovy.

Does it need to be an IDE or a plugin?
You can use a Listener to print or Report the tests on start:
import org.testng.annotations.Listeners;
#Listeners(TestListener.class)
public class TestClass {
#Test
public void testMethodA() {
/* Some testing here */
}
}
import org.testng.ITestContext;
import org.testng.ITestListener;
import org.testng.ITestNGMethod;
import org.testng.ITestResult;
public class TestListener implements ITestListener {
#Override
public void onTestStart(ITestResult result) {
}
#Override
public void onTestSuccess(ITestResult result) {
}
#Override
public void onTestFailure(ITestResult result) {
}
#Override
public void onTestSkipped(ITestResult result) {
}
#Override
public void onTestFailedButWithinSuccessPercentage(ITestResult result) {
}
#Override
public void onStart(ITestContext context) {
for (ITestNGMethod method : context.getAllTestMethods()) {
System.out.println("Test: " + method.getMethodName());
System.out.println("Description: " + method.getDescription());
}
}
#Override
public void onFinish(ITestContext context) {
}
}
Of course the System.out is just for the example. You could do in there what you need with that information.

I think you're asking for the ability to selectively run or debug tests from within Eclipse.
Yes, you need to first install TestNG add-in via 'Install new software' available under the 'Help' menu.
Once you have it installed, make the class file containing tests as active window. Then TestNG add-in gives you not only the ability to see all the tests but also let you select & run specific tests in an explorer like window as shown in the below screenshot.

Related

Eclipse job with UI access

I have one situation.
I have one Eclipse job with following code:
private class ExecutionJob extends Job {
public static final String MY_FAMILY = "myJobFamily";
public ExecutionJob(String name) {
super(name);
}
#Override
protected IStatus run(IProgressMonitor monitor) {
monitor.beginTask("executing ...... ", IProgressMonitor.UNKNOWN);
methodForExecution();
monitor.done();
return Status.OK_STATUS;
}
#Override
public boolean belongsTo(Object family) {
return family == MY_FAMILY;
}
}
And this methodForExecution() has code as below :
public void methodForExecution(){
PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().showView("view_id");
}
Now, the situation is, job opens up something like progressmonitor, and my method is trying to access UI which is actually behind this job's progressmonitor. And it gives NullPointerException as the progress monitor does not have ActiveWorkbenchWindow.
I can not use UIJob, as I have to execute this methodForExecution() asynchronously.
Can someone please help me resolving this.
The code you want to run must run in the UI thead.
If most of the work in the job is updating the UI and there is no long running non-UI code then you should use UIJob to run this. This is still scheduled as a job but the runInUIThread method is executed in the UI thread.
If you have a lot of non-UI code especially long running code then use a normal Job but you will have to use Display.asyncExec to run the method in the UI thread:
Display.getDefault().asyncExec(new Runnable()
{
#Override
public void run()
{
methodForExecution();
}
});
In Java 8 you could do:
Display.getDefault().asyncExec(this::methodForExecution);
You can also use syncExec instead of asyncExec to wait for the UI to update.
If the showView is all you want to do you could just do the asyncExec without using a Job.

#ProxyCodeSplit how exactly it works?

I am new to GWT and GWTP. I know what is GWT Code Split and GWTP Proxy Code Split. I've already red:
http://www.gwtproject.org/doc/latest/DevGuideCodeSplitting.html
http://dev.arcbees.com/gwtp/core/presenters/creating-places.html
I assumed that I understand it. So I've like to used.:
I have application with Administration panel, where only part of users can access. So there is no need to download Administration panel related code for all. So in Administration Presenter I've added #ProxyCodeSplit like follow:
public class AdminAreaPresenter extends Presenter<AdminAreaPresenter.MyView, AdminAreaPresenter.MyProxy> {
#ProxyCodeSplit
#NameToken(Routing.Url.admin)
#UseGatekeeper(IsAdminGatekeeper.class)
public interface MyProxy extends TabContentProxyPlace<AdminAreaPresenter> {}
#TabInfo(container = AppPresenter.class)
static TabData getTabLabel(IsAdminGatekeeper adminGatekeeper) {
return new MenuEntryGatekeeper(Routing.Label.admin, 1, adminGatekeeper);
}
public interface MyView extends View {}
AppPresenter appPresenter;
#Inject
AdminAreaPresenter(EventBus eventBus, MyView view, MyProxy proxy, AppPresenter appPresenter) {
super(eventBus, view, proxy, AppPresenter.SLOT_TAB_CONTENT);
this.appPresenter = appPresenter;
}
}
In other Presenters I have #ProxyStandard instead of #ProxyCodeSplit.
I've run app and log in. then I've opened Network tab in chrome's developer console:
And after opening Administation Panel in application:
As You can see, there is no new resources added to application.
My main app presenter AppPresenter implements interfaces AsyncCallStartHandler, AsyncCallFailHandler, AsyncCallSucceedHandler from: com.gwtplatform.mvp.client.proxy. and I override those methods:
#ProxyEvent
#Override
public void onAsyncCallStart(AsyncCallStartEvent event) {
Window.alert("Async start");
getView().setTopMessage("Loading...");
}
#ProxyEvent
#Override
public void onAsyncCallFail(AsyncCallFailEvent event) {
Window.alert("Async fail");
getView().setTopMessage("Oops, something went wrong...");
}
#ProxyEvent
#Override
public void onAsyncCallSucceed(AsyncCallSucceedEvent event) {
Window.alert("Async success");
getView().setTopMessage(null);
}
And when I enter AdmininArea I am getting to allerts: "Async start", "Async success". So I think that everythink work, but unfortunatelly I don't see any changes in resources. Please help. Am I doing something wrong or what?
Code splitting is disabled in SuperDevMode because it is not compatible with the incremental compiler and would also slow down compilation (see this issue).
To test code splitting, compile your GWT application (mvn clean install gwt:compile) and test it in production mode (take war file from target directory and put it in f.e.: Tomcat server catalog: webapps).

Play 2 Java, play-authenticate and Eclipse JUnit tests

I have a new Play 2 project with play-authenticate. I wrote some simple test cases for the REST API. Tests pass fine on the console but I cannot make some of them pass in Eclipse.
#Test
public void testWithoutAuth() {
running(testServer(3333), new Runnable() {
#Override
public void run() {
Response response = WS.url("http://localhost:3333/secretarea").get().get();
assertThat(response.getStatus()).isEqualTo(FORBIDDEN);
}
});
}
This example passes fine on the console but in Eclipse fails with response error code 500. it looks like the application setup is not ok (e.g. my own AuthProvider not found). Has anyone managed to get such tests working in Eclipse?
Finally sorted this out. The trick is to create FakeApplicatio with custom config. In my case the setup is like this:
#Test
public void testWithoutAuth() {
List<String> plugins = new ArrayList<String>();
plugins.add("be.objectify.deadbolt.DeadboltPlugin");
plugins.add("service.MyUserServicePlugin");
plugins.add("providers.MyUsernamePasswordAuthProvider");
FakeApplication fa = fakeApplication(new HashMap<String,String>(), plugins);
running(testServer(3333, fa), new Runnable() {
#Override
public void run() {
Response response = WS.url("http://localhost:3333/secretarea").get().get();
assertThat(response.getStatus()).isEqualTo(FORBIDDEN);
}
});
}

Is there a way to have Eclipse flash its taskbar icon once a time consuming task finishes?

I often minimize Eclipse to read or work on something else for a few minutes while I wait for it to do something (e.g., run a large JUnit test suite, synchronize a huge number of files with a repo, run a long Ant build, etc.). I have to check back every 30 seconds or so to see if it's finished yet. I would like Eclipse to alert me, preferably by blinking its taskbar icon, after it finishes a time consuming operation. Are there any settings or plugins that can make this happen?
I believe is you have Mylyn installed, this should be enabled by default for Windows 7. See here and here. Regarding the post-build actions, I do not know of any existing Eclipse plugins that do this. However, I have not exhaustively searched the marketplace. However, this could be accomplished with existing Eclipse APIs but it would require someone to author a new Eclipse plugin.
The Eclipse Platform jobs framework has an API called IJobManager. A developer could write a new Eclipse plugin that could use this API to listen for job changes and do the following:
Create an eclipse plugin, register a listener to IJobManager on startup.
Once any interesting job is completed, it could fire off some external task/script using normal java process execution API in the JDK
This all could be accomplished in one Java file, probably less than 500 lines long.
You could use this template to setup a basic Eclipse plugin project including build system and have it built and ready to install into your existing Eclipse.
Update I just found a maven archetype for building eclipse plugins with tycho here. It would be my recommendation for someone new to building an eclipse feature/updatesite.
You can create a new plugin project and create this kind of functionality for yourself. The
IJobchangeListener from the Eclipse Jobs API is probably very interesting for you.
The IJobChangeListener is an interface where you can receive notifications for the different type of job states.
I have created a class called JobListener which adds the IJobchangeListener to the JobManager. With the action SampleAction you can register or unregister the listener. that means, if the listener is registered and your application is minimized you will be notified with a MessageDialog (no blinking taskbar).
I found a link where someone made his swing application blink. This functionality should be included in the method public void done(final IJobChangeEvent event). I haven't done this in my test class.
You can also get additional information about the Job with
event.getJob();
Here you are able to check the Job name:
String jobName = event.getJob().getName();
The name of the Job is human readable, for example "Collecting garbage", "Update for Decoration Completion", "Building workspace", etc.
The JobListener class.
/**
* A job listener which may be added to a job manager
*/
public class JobListener {
private MyJobListener listener = null;
private IWorkbenchWindow window = null;
private boolean active = false;
public JobListener(IWorkbenchWindow window) {
this.window = window;
}
/**
* register the job listener
*/
public void register() {
listener = new MyJobListener(window);
IJobManager jobMan = Job.getJobManager();
jobMan.addJobChangeListener(listener);
active = true;
}
/**
* unregister the job listener
*/
public void unregister() {
IJobManager jobMan = Job.getJobManager();
jobMan.removeJobChangeListener(listener);
active = false;
}
public boolean isActive() {
return active;
}
class MyJobListener implements IJobChangeListener {
private IWorkbenchWindow window;
public MyJobListener(IWorkbenchWindow window) {
this.window = window;
}
#Override
public void sleeping(IJobChangeEvent event) {
}
#Override
public void scheduled(IJobChangeEvent event) {
}
#Override
public void running(IJobChangeEvent event) {
}
#Override
public void done(final IJobChangeEvent event) {
window.getShell().getDisplay().asyncExec(new Runnable() {
#Override
public void run() {
if(window.getShell().getMinimized()) {
MessageDialog.openInformation(
window.getShell(),
"Test",
"Job " + event.getJob().getName() + " done.");
}
}
});
}
#Override
public void awake(IJobChangeEvent event) {
}
#Override
public void aboutToRun(IJobChangeEvent event) {
System.out.println("About to run: " + event.getJob().getName());
}
}
}
I called this class from a class called SampleAction.java
public class SampleAction implements IWorkbenchWindowActionDelegate {
private IWorkbenchWindow window;
private JobListener listener;
/**
* The constructor.
*/
public SampleAction() {
}
public void run(IAction action) {
if(listener.isActive()) {
listener.unregister();
MessageDialog.openInformation(
window.getShell(),
"Lrt",
"Unregistered");
}
else {
listener.register();
MessageDialog.openInformation(
window.getShell(),
"Lrt",
"Registered");
}
}
public void selectionChanged(IAction action, ISelection selection) {
}
public void dispose() {
}
public void init(IWorkbenchWindow window) {
this.window = window;
this.listener = new JobListener(window);
}
You can get started with eclipse plugin development by creating a new plugin project:
File > New > Project > Plugin Project
I used the Hello World plugin project template to test the code above.

Running External Apps on save in Eclipse

Since we cannot setup Eclipse's RSE to use at the tool for remote editing, I have installed Unison. But how can I get Eclipse to automatically run unison on every file save? Is there an eclipse plugin available for this?
TIA
You can setup it to be run on every build. Any external tool can be run on every build, just open project's preferences, go to Builders page, click “New…”.
Depending on the importance, I would write a simple plugin to handle this.
EDIT:
All you really need to do is this:
1) Create the plugin from the templates with the RCP\PDE Eclipse install
2) Add the following code to your activator...
#Override
public void start( final BundleContext context ) throws Exception {
super.start( context );
plugin = this;
ICommandService commandService = (ICommandService)plugin.getWorkbench().getService( ICommandService.class );
commandService.addExecutionListener( new IExecutionListener() {
public void notHandled( final String commandId, final NotHandledException exception ) {}
public void postExecuteFailure( final String commandId, final ExecutionException exception ) {}
public void postExecuteSuccess( final String commandId, final Object returnValue ) {
if ( commandId.equals( "org.eclipse.ui.file.save" ) ) {
// add in your action here...
// personally, I would use a custom preference page,
// but hard coding would work ok too
}
}
public void preExecute( final String commandId, final ExecutionEvent event ) {}
} );
}