0

You could use comments to mark code. Besides that, is there a way to mark a block or line of code as experimental/only for test purposes ?

Pseudocode in java -

public SpecialObject importantMethod(){

System.out.println("Ready to go into if else"); // Test Code: Delete Later !

if(condition after a big series of method calls){

System.out.println("Entered into if"); // Test Code: Delete Later !

//execute code which is critical to program

}else
{

 System.out.println("Entered into else");  // Test Code: Delete Later !

 //execute code which is critical to program

}

 return specialObject;
}


public void anotherImportantMethod(){

 SpecialObject obj = importantMethod();

 //do something important with obj
}
Jedi Knight
  • 571
  • 2
  • 7
  • 18

2 Answers2

2

Your example looks like this is what Log4j levels are required for. You can nominate different log levels for different categories (often corresponding to class names) and switch these on/off at deploy or runtime.

If your requirement isn't just restricted to logging, I would inject some component that you invoke suitable methods upon, and create different implementations (say, one called TestExperimentalFunctionality and one called NoFunctionality). They would both implement the same interface, and your core code wouldn't have to change. However you could provide differing implementations at deploy/runtime, thus giving you differing functionality.

Brian Agnew
  • 268,207
  • 37
  • 334
  • 440
  • Is log4j better than task tags mentioned by bmorris591 ? My requirements are very simple. – Jedi Knight Mar 25 '13 at 12:41
  • Regardless of your requirements, I would investigate Log4j (or other logging frameworks) to allow you to manage your logfiles and logging requirements with a great deal of simplicity and flexibility – Brian Agnew Mar 25 '13 at 12:43
0

First I want to add my own requirement that may interest you too, Then I will share my knowledge so far.

My requirement is that an indication like error will be shown on "Project Explorer" like a compilation error will. The use is so I won't accidentally commit, upload or publish a none complete or error code to air(That is not a compile error rather a business logic one).

Example:

I want it to show an error mark on project tree: This is like how compilation error will be marked at "Project Explorer"

// SKIP this product
if(identifier==null){
// FIXME - REVERT THIS = TEST ONLY - Don't skip product
/*
  continue;
*/
}

For you:

  1. There are bookmarks that you can use to highlight code. See answer here: Eclipse plugin to mark code
  2. There are "Task Tags" you can use to mark a comment in TODO, FIXME, XXX and customized. Window -> Preferences, and search for General -> Editors -> Structured Text Editors -> Task tags, or for Java -> Compiler -> Task tags. See answear here: IDE comment keywords
Tomer Madmon
  • 61
  • 1
  • 3