Results 1 to 5 of 5
  1. #1
    wiz6 is offline Member
    Join Date
    Jan 2012
    Posts
    12
    Rep Power
    0

    Default Testing java classes

    Do you always redeploy your java ee application for testing/fixing something. It is very annoying and take also time.
    Example, i want to add if statement to save() method which saves something to db using INSERT clause. I have to deploy the all web application again.
    My project directory is:
    Project
    --src
    --JRE System library
    --main(my web application folder)

    I tried to make a test class in main folder, but eclipse saves it in src folder, so i cant import my web application functionality to my test class.
    I hope you understand me. :)

  2. #2
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    3,728
    Rep Power
    5

    Default Re: Testing java classes

    Nooo, it is not necessary - not always anyway. The Java debugger supports hot-swapping of code. Eclipse makes it possible to start a container/server in debug mode, which activates that hot-swapping support. If you but do that, then changing the code in Eclipse should automatically reflect the change in the deployed application without having to restart anything.

    You can't hot-swap everything; it works when you change the internals of a method but if you add or remove anything such as a property or a method, it won't work anymore. In fact Eclipse will tell you that it can't hot-swap the changes and will ask you to restart the server.

    A second technique I have learned to do is to actually add a "quick start" for development purposes. This consists of two tricks:

    1. navigating to an URL without being logged in yet usually sends you to the login page; I make the application remember that URL and make it redirect to it after logging in

    That is quite common to do. Now the following is only allowed in a development environment:

    2. going to the application automatically logs me in as a default development user

    Combine the two tricks and even after restarting the application (which in modern containers/servers only takes a few seconds) I can quickly go back to the spot that I was making changes to with only a minor delay.
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  3. #3
    wiz6 is offline Member
    Join Date
    Jan 2012
    Posts
    12
    Rep Power
    0

    Default

    Do i need to install some extra plugin for that?

  4. #4
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    3,728
    Rep Power
    5

    Default Re: Testing java classes

    Nope. As I said, it is a feature of the Java debugger. Starting the web container in debug mode should be enough, but it may also depends on how you deploy the application. The trick is to get the updated .class file to the server, which in case of Eclipse would require you to turn on "build automatically" (which it is by default).

    How do you deploy the application to the server anyway? If you can't get it to work to see changes in the running application, perhaps there is something wrong there.
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  5. #5
    wiz6 is offline Member
    Join Date
    Jan 2012
    Posts
    12
    Rep Power
    0

    Default Re: Testing java classes

    Quote Originally Posted by gimbal2 View Post
    Nope. As I said, it is a feature of the Java debugger. Starting the web container in debug mode should be enough, but it may also depends on how you deploy the application. The trick is to get the updated .class file to the server, which in case of Eclipse would require you to turn on "build automatically" (which it is by default).

    How do you deploy the application to the server anyway? If you can't get it to work to see changes in the running application, perhaps there is something wrong there.
    This project is built by using gradle(not by me). In gradle there are same tasks. One of them is "run" which starts server and localhost:8080 is available. Can i use this method if i want use java debugger or i have to use some other method? Usually i deploy my work: export project->make war file and run it on localhost:8080. Just java debugger doesnt say me anything :(

Similar Threads

  1. Whitebox testing and testing tables, help please
    By Stefano in forum New To Java
    Replies: 2
    Last Post: 02-07-2013, 05:02 AM
  2. Junit Testing within local classes
    By danboy4 in forum New To Java
    Replies: 3
    Last Post: 10-08-2012, 01:44 PM
  3. Junit testing, testing list<e> interface
    By mackavelirip in forum New To Java
    Replies: 0
    Last Post: 10-05-2011, 06:08 AM
  4. Replies: 1
    Last Post: 04-17-2008, 02:30 PM
  5. Java testing tools
    By mew in forum Advanced Java
    Replies: 0
    Last Post: 01-25-2008, 07:26 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •