How to write Junit test case for old java project? [closed] - java

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 am working on a very old application built using strut 1.1 in 2004. The complete application is made by combining three projects(common, web, and EJB) in Eclipse and all these three are packaged as.EAR file. So here the confusion where to fit the JUnit test cases for this type of structure.
Whether I should create a separate project for writing the test cases. If I create the separate project, I would add the above projects in the build path.
So what is the right way? Any suggestion would be appreciated.
Also, tell me about the way I can check the results on GUI that how many cases are passed and how many are failed.

First of all: in case you intend to write real JUnit unit tests for 14 year old code, the answer is: do not do that.
If at all, you should be using JUnit as environment to automate test case execution, which in this case should be "integration" or "functional" tests.
You see: the only reasonable argument to invest money in old, existing source code is: you intend to refactor/replace that solution with a new implementation. Then your one and only concern is that your new code behaves like the old one. From a functional point of view. It doesn't make sense to invest time/energy into unit testing units you intend to throw away soon.
Beyond that: do whatever works for you. Typically, it would be better to have a complete new project to avoid tampering anything existing.

Related

Writing a modification for multiple versions of the original application [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 2 years ago.
Improve this question
I am writing a modification for a specific version of a Java application. I modify the existing code and add my own special code into it.
Now, when the original Java application gets an update with major codebase changes and I would like my modification to be available for that new version, it would be really hard and time consuming for me to copy all of my own code and update all changes that I made to the original source code. When I code a new feature, I will then have to copy the whole feature for multiple versions of the original application.
My goal is to support multiple versions simultaneously, but I am wondering if there is a simpler (or more efficient) way of doing this so I keep my own code in a common location and only adapt some other parts of the code.
Thanks in advance!
There is no simple solution.
You forked an application, the original developers know nothing of your fork, and regardless, even if they did they are not required to do anything to maintain compatibility.
If your fork potentially has value to others, you should lobby to contribute it to the original project, and become a contributor on that project. Otherwise, it will be up to you to diff every new version of the base against the previous version and then adjust your code to deal with any incompatibilities introduced by the new version.

How to inject and run Scala code in a running JVM [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 3 years ago.
Improve this question
Is it possible to compile & run scala code dynamically within Java code.
It is possible to achieve a similar result with JS using mozilla rhino. But, I wonder if it is possible with scala?
Theoretically, yes. But you will need to do a lot of things:
ensure the user entered valid scala code
transfer that source code to the server
compile the scala code
run it from within your server (catch errors, deal with resource leaks, ...)
So, possible: yes. Reasonable: not so much.
Obviously: a lot of work
getting to a decent user experience: even more work (like: telling the user exactly where in his source code input your compilation step found a bug ... hard)
And of course: opens your system for a ton of attack vectors.
If you want your users to be able to run code on the backend server, one wonders: why don't they have admin access to that machine already, and are able to deploy there code right there on the server themselves?!
Sure, Scala has its REPL, and as that one comment pointing to an existing answer implies: it is definitely possible to do that.
But as said: we don't do things because we can, but because it makes sense doing it!
twitter util-eval library seems provide what I need, but it is discontinued.
Here is an old fork:
https://github.com/m3dev/twitter-util-eval

unit testing for proprietary ide [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I would like to add some sort of unit testing to an IDE known as "IBS Integrator".
how the IDE works:
I write "java-ish" code in .itr files.
when I press the run button these files are compiled into .class and .java files.
I have no idea what happens next.
Does anyone have advise on how I could make unit testing work in a setup like this?
I was hopping for a framework like phpunit or rspec. I know they are for different langagues but a similar tool for java would be nice. I'm not sure what (if anything) can interact with .class/.java files.
I would prefer something open-source if possible.
Since IBS Integrator compiles to .class files, you should be able to write JUnit tests in Java against those classes, and run them however you'd normally run JUnit tests (kick off Ant or Maven, open Eclipse and run them from there, etc.). And I can't think of any reason to use another technology (phpunit, rspec, etc.) for writing tests of Java code; JUnit seems like the clear winner here.

Eclipse - java source file organization [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 9 years ago.
Improve this question
this is a source file organization question -
I used to create separate Eclipse Projects for solutions to example problems I solved ( eg: the first one is for Exercise 1.1.2 ). Each project has a single java file with a main() function that does the work/testing. So as I keep adding new solutions the number of projects grows which is pretty unwieldy. And each project has just one java file, so there must be a better way to organize these.
What are some good ways/best practices to consolidate all these into a single project?
( Just stick the files together/ have a single main method, etc.. )
Here's what I would do. Create one project in Eclipse called "Exercises". The project should have one src folder and one test folder. Group your code into packages as suggested in another answer; com.exercises.chapterone, there either create a java class for each exercise, or one large class for each chapter with separate methods for each exercise.
Then create JUnit tests that mirror your code and run each class/method to verify that it works. You don't need a main class to run code. This will keep your workspace small and tidy and it will help you to learn how to unit test your code. This is a very important thing to learn, so the sooner you start to do it, the better.
So, something like this
Exercices
src
com.exercise.chapterone
Exercise1.java
oneOneOne(...)
oneOneTwo(...)
Exercise2.java
test
com.exercise.chapterone
TestExercise1.java
TestOneOneOne(...)
TestOneOneTwo(...)
TestExercise2.java
A place to start would to put them in one project and group them logically in packages.
E.g. you can put all 1.1 exercises in a package named com.exercises.oneone.
Firstly, you can group your exercises using packages, one exercise per package.
And then with each exercise, provide one entrance method for test, instead of a main function. And at last, you can run test using some testing libs such as junit, or you can even write a single main function to test all your exercises.
If you require independence between exercises, with junit, you can run each test case independently. While using single main function, you can pass some args into the main and determine which exercise to run.
Hope this will help you.

Automated UAT/functional tests on Swing applications without source code [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 5 years ago.
Improve this question
Our team is now working on a big Swing application. Our job basically focuses on writing extensions to the existing framework. A typical job would be adding a new panel/ or adding a new tab with some extra functionalities that suit our need.
It seems FEST can help a lot in terms of unit-test our code. I am going to try it out this week. But the question here is if there is a way to do automated functional testing on the whole application. In another word, we do not only need to test our code but also the framework. After all, UAT is the most important part.
I am currently considering decompiling the jar files we got into source code then we can identify the components and then use FEST.
So, before I get started to give this approach a shot, I think I just ask for ideas and inspirations here. There must be people who have done similar things before. Would be nice if I could learn from the veterans who fought against this before .
Thanks,
In my view, Functional tests and unit tests are not well serviced by the same framework. For functional testing, I would recommend you look at QFTest, which understands Swing components, so you get a more stable test than a traditional click-and-keyboard playback mechanism, while still being at the functional level.
You could consider ReTest, which is a functional Swing test tool that comes with an interesting approach to regression testing and is packed with AI-based monkey testing.
It is going to be partly open source as well.
Disclaimer: I am the founder of the company creating ReTest.

Categories

Resources