How to create unit tests easily in eclipse [closed] - eclipse

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking us to recommend or find a book, tool, software library, tutorial or other off-site resource are off-topic for Stack Overflow as they tend to attract opinionated answers and spam. Instead, describe the problem and what has been done so far to solve it.
Closed 8 years ago.
The community reviewed whether to reopen this question 1 year ago and left it closed:
Original close reason(s) were not resolved
Improve this question
I want to create unit tests easily by just selecting method. Is there a tool in eclipse that does that. It should support templates. I should be able to create positive test as well as negative tests.

To create a test case template:
"New" -> "JUnit Test Case" -> Select "Class under test" -> Select "Available methods". I think the wizard is quite easy for you.

You can use my plug-in to create tests easily:
highlight the method
press Ctrl+Alt+Shift+U
it will create the unit test for it.
The plug-in is available here. Hope this helps.

Check out this discussion [How to automatically generate junits?]
If you are starting new and its a java application then Spring ROO looks very interesting too!
Hope that helps.

Any unit test you could create by just pressing a button would not be worth anything. How is the tool to know what parameters to pass your method and what to expect back? Unless I'm misunderstanding your expectations.
Close to that is something like FitNesse, where you can set up tests, then separately you set up a wiki page with your test data, and it runs the tests with that data, publishing the results as red/greens.
If you would be happy to make test writing much faster, I would suggest Mockito, a mocking framework that lets you very easily mock the classes around the one you're testing, so there's less setup/teardown, and you know you're really testing that one class instead of a dependent of it.

Related

Eclipse Project description - NOT .project file - is there such a thing? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 4 years ago.
Improve this question
I have a whole bunch of Eclipse projects, large and small, that I want to keep organized. I'm trying to figure out if there is some sort of property that can be attached to the project in order to provide a description of what the project is or what it was created to do or test. I would hope that this field can be easily viewed at the time you are browsing through a list of projects. It would be nice if I could put descriptive text into this field and not have to consider giving my projects names like 'TwitterOAuth2TestImplementationUsingScribe'
Anything that would allow you to browse your projects in a way similar to this (each line represents an Eclipse project):
Myproj1 Simple Test Project
LogTest3 Test new logging class
NetworkUDPTests Testing UDP classes
OAuth2Example Sample project for Oauth2
Unfortunately, project "description" is the name of the .project file that stores each project's settings, so it is a bit harder to search for information on this.
Thats an interesting question we also face. Currently there does not seem to exist a solution for this problem. The only thing that could come near to providing one is the Mylyn Intent project, as it aims to provide a comprehensive documentation on design decisions, which takes into account the inter-dependencies between plugins.
This inter-dependency is exactly the problem. There exist solutions to document the purpose of java packages which is limited to the classes however.
Our solution is a readme.textile embedded in the root of each plugin, providing this specific information. It would, however, be interesting to introduce the documentation used for packages for bundle documentation, which could be used to autogenerate an overview documentation.
There is a comment tag in the .project file: http://help.eclipse.org/luna/topic/org.eclipse.platform.doc.isv/reference/misc/project_description_file.html
However it looks like Eclipse itself doesn't use the content of this tag. I changed it manually but after that I've never seen the text I entered anywhere in Eclipse

Eclipse plugin for TypeScript? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking us to recommend or find a tool, library or favorite off-site resource are off-topic for Stack Overflow as they tend to attract opinionated answers and spam. Instead, describe the problem and what has been done so far to solve it.
Closed 9 years ago.
Improve this question
The new Microsoft TypeScript language (typed superset of JavaScript) seems very interesting, is there any alpha / incubator project that attempts to support it in Eclipse? Or is it too early to even wish for it
Check this open source plugin which is build by palantir.
This question was asked the day TypeScript was released, so as of today (Oct 2nd 2012), there is no support. Having said that, the XText team -- a team responsible for rapidly creating DSLs -- is aware of TypeScript and I wouldn't be surprised if they do something.
Another place to look is Microsoft. Depending on what their motivation is with TypeScript, they may push for an Eclipse project (although I doubt it).
Orion (the web based eclipse ide) would be a good fit. It is already using nodejs, so it would be easier to incorporate tsc and the language services. Right now they already support Javascript including some type inference. I understood typescript is on their radar.
Looks like the beta of an Eclipse Typescript plugin was uploaded on Aug 7 2013. I haven't had a chance to try it out yet but it looks promising.
http://marketplace.eclipse.org/content/typescript#.UgfEuD9IG-V
https://github.com/palantir/eclipse-typescript
Until a specific plugin is implemented, if you are adventurous enough, you might try and just use JSDT and associate *.ts files with the JavaScript editor. If you get JavaScript validation errors, disable the JavaScript Validator under Project > Properties > Builders. For automatic TypeScript compiling, you can set up an external builder as described here or here.
My settings:
Main
Location: /usr/local/bin/tsc
Working directory: ${build_project}
Arguments: ${build_files:f}
Refresh
Refresh resources upon completion: checked
The folder containing the selected resource
Environment
PATH = /user/local/bin
Build Options
Allocate console: checked
Run the builder: During auto builds
Specify Resources: a folder that contains *.ts files

Eclipse for Visual Studio dummies [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking us to recommend or find a tool, library or favorite off-site resource are off-topic for Stack Overflow as they tend to attract opinionated answers and spam. Instead, describe the problem and what has been done so far to solve it.
Closed 9 years ago.
Improve this question
Looking for links to good information for Eclipse beginners. I've been a c# developer for sometime and I feel like I'm swimming in molasses. I'm especially interested in anything like the snippets functionality and how to use it (for example the prop snippet to create a property)
I'd recommend you start with the tutorials on the "Welcome" screen (automatically shown on first launch, or via Help menu).
After that, a lot of stuff can be discovered by poking around. The built-in help is also quite good, and failing that, just google for it.
Set yourself some goal, and do a bit of research; I've found most stuff fairly easily that way.
As for snippets: I'm not terribly familiar with VS, but I gather they are basically code templates that you can insert and then fill in.
In Eclipse, that would be auto-complete (or "Content Assist"), triggered by Ctrl-Space. Just try it, it's fairly clever. It will offer completions of variable names, functions etc., but will also offer common snippets like creating constructors, public methods etc. E.g. type "public ctrl-spc", and it should offer a template for a public method (try ctrl-space several times to cycle through proposals).
You can also create your own auto-complete code snippets. These are called templates in Eclipse, to be found in the prefs under "Java / Editor / Templatest". Templates can be triggerd in auto-complete by typing the (beginning) of the template's name, then auto-completing.
Have fun!
I was also a VS user for a long time and found Eclipse confusing, requires a lot more configuration to get it up and running first off.
Found this very helpful post on a Google search
http://benpryor.com/blog/2006/03/03/top-10-tips-for-new-eclipse-users/
.
I don't use it often but here are a few things that threw me at first.
Workspaces confused me, there is no exact equivalent in VS, I'd say they are a bit like Solutions. I made the mistake of keeping all my projects in one workspace and after a year of work Eclipse could barely open the workspace.
You don't need to hit 'Build' to compile your code, it keeps compiling in the background so there is always an up to date list of bugs, called problems in Eclipse.
When you run your code in debug all the windows jump about some disappear and lots of strange new ones open. These different layouts are called perspectives. There is a tab bar next to the main tool bar which lets you move between open perspectives or you can close them using the Window menu.
Besides the very good Eclipse tutorials and documentation sleske mentioned here are some other good tutorials and introductions:
IBM tutorial for Visual Studio users - you have to register for reading this tutorial but registration is free and you can download a bunch of really good Eclipse materials
Effective Eclipse - Custom Templates - this article shows you Eclipse's "snippets funcionality" in details

Eclipse metrics plugin suggestion [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 5 years ago.
Improve this question
I'm looking for a tool to give me some code metrics (total LOCs, LOC/Class, # of external references/class, etc...).
Does anyone know a good eclipse plugin that could provide me some some code metrics?
CodePro AnalytiX originally form Instantiations is now free at Google:
http://code.google.com/javadevtools/download-codepro.html
here is one called Metrics.
edit:
i put together a short program for this screenshot in eclipse 3.3.1.1:
Edit 2
Metrics New version Thanks #mpartel for the link
Sorry for the necropost but it seems like the right thing to do since this was my starting point. Try Metrics2, its a fork of the original metrics plugin and is built for Eclipse 3.5.
There is an updated version of the Metrics plug-in described above that should do what you need. It can aggregate some of the measurements (e.g. add up the LOC of classes in a package to give you the LOC of the package) and export the measurements to XML. Some time in the near future, it should also export them to a relational database.
If you want LOC only then use locmetric http://www.locmetrics.com/ . and if you want check metric and code coverage usse SONAR or Eclips CodePro Analytix plugin.
i suggest to use https://developers.google.com/java-dev-tools/codepro/doc/ it has Automated tools measure quality of Java source code and code coverage
A search for eclipse code+metrics turns up http://eclipse-metrics.sourceforge.net/, which looks good.
I also recommend the eclipse-metrics plugin.
It is capable of exporting the metrics into html, and is capable of doing this from an ant task (at least according to the documentation, I have never tried it).
The plugin works even in Eclipse 3.5 fine.
Sonar seems worth to look at: http://docs.codehaus.org/display/SONAR/Installing+Sonar+in+Eclipse
Another good project is the projectusus, which shows you not only the metrics but also whether you are respecting the standards or not and gives you a hint of what should be refactored

Is there any good tool to refactor Perl web code? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking us to recommend or find a tool, library or favorite off-site resource are off-topic for Stack Overflow as they tend to attract opinionated answers and spam. Instead, describe the problem and what has been done so far to solve it.
Closed 9 years ago.
Improve this question
I'm currently working on a Perl web app LAMP style and recently stumbled upon this death maze of code left by some previous developer. He left so many magic numbers and weird logic that it gives me a headache every time I had to go through it.
I'm learning unit testing right now so I want to find some useful tool to refactor the code and write unit test along the way to make sure that I don't accidentally break anything.
Any recommendation for any good refactoring tool for Perl?
Preferably free :)
I think Eclipse / EPIC has "some" Perl refactoring tools... but don't quote me on that ;-)
Might also be worth checking out Komodo. However the full version isn't free like Eclipse / EPIC. You could try their opensource version Komodo Edit but I guess it won't have all the features?
I've not used either above or any other refactoring tools... I get by with vi/vim & TextMate editors and what they provide (or what I've so far found in each of these editors!).
Making unit tests is a good start. Also have a look perltidy / Perl::Tidy & Perl::Critic which may help peer thru the mess and find some of those "code smells".
Probably, volunteers on Refactor :my => 'code' can help you. Anyway, it's free to ask :)
Perl's dynamic nature means that it is very hard to create refactoring tools for it.
However with regards to testing you should be able to put together some regression tests to help you on your way. This works by starting with the code as it is now and capturing its current output. This might be running the CGI script from the commandline and saving the resultant HTML to file.
Once you've captured this you can change the code and as you go check to see that the HTML has not changed, which means that the code has not broken. When changes do occur you can then either find the bug, or change the test to accept the new HTML as correct.
This can be a bit of a chore to set up but will make your life easier in the long run. You should try to automate these tests to make the easy to run. Checkout Test::WWW::Mechanize and Test::LongString as well as all the others.
While it's not really refactoring in any great depth, this PerlMonks node describes a couple of Vim mappings for deobfuscating perl code using B::Deparse.
Their examples:
You can type _d when your cursor is over this line in normal mode:
--$|&&s|\n|-|;
... and it will be replaced with:
s/\n/-/ if --$|;
And this line:
$foo and $bar or $baz = 1;
... would be replaced with:
$baz = 1 unless $foo and $bar;
Eclipse with the EPIC plug-in does have some refactoring support. Not as sophisticated as IntelliJ's refactoring for Java tool. Not 100% sure it would help with your problem though. They way I've used it is to highlight blocks of code and move them into functions / methods. In your case you're probably going to want to do a lot of search/replace on those magic numbers...
I assume you're going to use Test::More to write your unit tests. Some of the other EPIC tools could help with that (eg "todo" tags).
You could also use Test::WWW::Mechanize and Test::WWW::Selenium -- would be useful in your case to have selenium tests defined to make sure you don't break any end-user functionality. EPIC doesn't have anything in particular to help with that though but it should be possible to use it to step-through the code when debugging.
Good luck. :-)
See Devel::Refactor - Perl extension for refactoring Perl code.
https://metacpan.org/pod/Devel::Refactor
vim! (Or any other text editor)
There really isn't a magic tool to refractor your code, there is tools around to (for example) rename variables/functions, but there is no way it can magically fix horrible code structure or weird logic.
Padre has some refactoring tools.
Renaming of variables works pretty good for a while (two years or so) now.
http://padre.perlide.org/
Disclaimer: I am a Padre contributor.