Netbeans JUnit automated testcases - netbeans

I am writing some unit tests in Java using NetBeans for a big project university java project, but it's boring to write these by hand. Is there a tool that can help me automate the creation of these tests?

Go to the Projects view, right click on the class. One of the last popup menu entries is tools and there you find a wizard to generate JUnit or TestNG classes.
This generates the boiler plate code for you. The test logic itself comes from you.
Maybe you could start here https://netbeans.org/kb/docs/java/junit-intro.html.

Related

Where should I look at in Eclipse source code to figure out how Eclipse generate JUnit testing result?

I'm analyzing Apache ant source code for my research. When a test suite runs, test cases are executed and Eclipse shows the test result as the image below. My goal is to get the executed test case names as Eclipse does. If I can see source code where Eclipse handles this, I think I can get the name list. Therefore, I'd like to know the source code location where Eclipse handle this or an easier way to achieve the goal... I tried using JUnit task in an ant build script to generate the test report so that I can get the test list by parsing the text/xml report. I could get the report with some warnings stating that duplicate classes are detected because I'm testing ant with ant. However, the report showed the test method name without its full class name...
Well, there is a short workaround for what you want to achieve (to have a specific, deterministic test run order), it is the #FixMethodOrder annotation on your test class. That will make your tests run in a specified order in every environment (or at least it should :-)).
If you want to do it in the hard way (analyze the source code of the Eclipse JUnit runner), I would advise installing the PDT tools and sources of the plugins first, and also set the Include all plug-ins from target in Java search under the Plug-in Development options (so you can find the plug-in types easily with Ctrl+Shift+T/R).
Then you have the Plug-in Spy which is a rock of a feature: press Alt+Shift+F2 and click on any element on the UI. Then you get all the info where the given component in defined (alternatively, you can press Alt+Shift+F1 zo display data of the selected component). An example is below:

Is it possible to mock all the objects around an eclipse RCP application?

I've been trying for a while now to do something a bit strange...
I need to invoke some code that gets executed by a eclipse rcp wizard window from outside the rcp environment.
Basically some third party team has built an installer using the eclipse rcp framework and one of the functionalities of this installer is to export some data.
I need to perform that same data export programmatically but from outside this whole rcp scope. (basically from ant).
The issues I seem to be facing are connected to not having the org.osgi.framework.BundleContext objects populated.
Any idea how I can mock them?
thank you in advance
Found the answer... import org.springframework.osgi.mock;

Using ant and netbeans how can I generate a UML diagram

We are trying to include the generation of an UML diagram on build via a task in ant.
So far I can't seem to find an easy way to do this and everything seem to point to eclipse.
We are using NetBeans 7.1.
Any pointers on this ?
Which UML diagrams do you want to generate? If you want to generate the class and sequence diagrams for a use case, MaintainJ is an option.
If you have JUnit test cases for your application, you can generate the class and sequence diagrams for every test case. Check this demo video.
You should probably view this demo video to get an overview of MaintainJ.
Once you understand how to generate the diagrams for every JUnit test case, it is quite easy to integrate it with Ant script. This way, for every new build, you could run all the test cases and generate the UML diagrams for all the test cases.
I am the author of MaintainJ, by the way.
I think this is not a question about the IDE you're using when you want to do this with ant. You have to find a ant plugin/task that can generate graphics out of your class hierarchy.
I only now plugins generating code out of UML diagramms but not the other way round, but a solution for you could be to develop your own ant task maby using ImageMagick to generate the diagramm.

NetBeans: execute all unit tests of all projects in 1 go

Unit testing some projects can take some time, and with multiple projects you have to start them one at-a-time sequentially. In NetBeans is it possible to run all unit tests for a single project in one go.
Is it also possible execute all unit tests for all projects in one go?
In NetBeans is it possible to run all unit tests for a single project in one go.
In NetBeans 7.1, yes, it is. See my previous answer to this same question.
Is it also possible execute all unit tests for all projects in one go?
I don't believe that this is possible.
In NetBeans is it possible to run all unit tests for a single project in one go.
This is possible by right clicking the project node in the Projects explorer and choosing Test from the context menu. You can also use the key board shortcut Alt+F6 to achieve the same result.
Yes in Netbeans also it is possible go to current project Properties by right clicking it, and go to Libraries, there u can add your other projects to run in a single go.

Eclipse Plug-in Development with TDD

I want to add a view to a perspective without having access to the source code of the perspective. Is this possible?
Is there a good tutorial for plug-in development using TDD?
[edit]
I think I have a good starting point with TDDing in plugin development
Automating unit tests (junit) for Eclipse Plugin development
[edit 02/17/09]
I was able to download the source for the plug-in. I'm just probably going to fork it.
Testing GUIs is a PAIN! And the pain grows exponentially with the complexity of the gui design. Your best bet is to keep the business logic separate from the GUI as much as possible with the MVC pattern and when testing the gui, hook the GUI up to a "mock" application.
See Object Mentor's paper, the Humble Dialog Box
You might want to take a look at the org.eclipse.ui.perspectiveExtensions Extension Point.
And here is a nice article concerning Perspectives: Using Perspectives in the Eclipse UI
Sorry, can't help you with the TDD part of your question.
If your goal is to simply add the view to a perspective in your own Eclipse instance, you can just open it when being in that perspective, and choose Window -> Save Perspective As...
For unit testing plug-ins, you can basically test them using normal JUnit tests, which you run as JUnit plug-in tests instead of normal JUnit tests in Eclipse. For GUI testing you could check out SWTBot.