Len Trigg writes:
 > 
 > Hi there,
 > 
 > I just had a look at the jde-junit that came with the latest beta of
 > JDE. I've had some functions for ages that I use for running test
 > classes, and so I've written a patch that lets my functions piggyback
 > off jde-junit.  The patch (attached) separates the jde-junit-run into
 > separate functions for getting the name of the class to pass to the
 > runner, and for running tests given a class name.  This keeps the
 > existing functionality, but lets me define the following modifications
 > (which you may want to include):
 > 
 > 1) If the current buffer doesn't appear to be a test class, derive the
 > name of the appropriate test class (e.g.: if I'm editing
 > com.example.Blah, runs com.example.BlahTest)
 > 
 > (defun jde-junit-get-test-class ()
 >   "Gets the test class for the current buffer"
 >   (let ((test-class (jde-run-get-main-class)))
 >     (if (string-match ".*Tests?$" test-class)
 >         test-class
 >       (concat (jde-db-get-package)
 >               (file-name-sans-extension
 >                (file-name-nondirectory (buffer-file-name)))
 >               "Test"))))

I am planning to provide a command like this. However, I want to make
the JDEE's support of unit testing more flexible. In particular, I
plan to provide customization variables that allow you to specify
where your test files are located, e.g, in the same directory as the
tested class, in a directory beneath, etc.  I also plan to provide a
customization variable that allows you to specify a rule for name test
classes, e.g., by prepending or appending a specified string. The JDEE
would then use the specified conventions to determine the name and
location of the test class that tests the class in the current source
buffer.

I'd also like to get some feedback from users on a couple of matters.

First, the current test class template requires that you insert testpoints
manually in the Test suite() method. I think it better to take advantage
of TestSuite's ability to determine test points by reflection, e.g.,

  public static TestSuite suite(){
    return new TestSuite (TDynamicClassLoader.class);
  }

Secondly, it would be nice to have a class member accessor
class that would allow test points that do not reside in the
same directory as the tested class to access the private and
protected members of the class. Any volunteers to create
and contribute a MemberAccessor class the JDEE?

Paul


 > 
 > 2) Being able to run all the tests for the package corresponding to
 > the current buffer (e.g.: com.example.AllTests). This may depend on
 > peoples own naming conventions for their package test class.
 > 
 > (defun jde-junit-run-alltests ()
 >   "Runs the corresponding test class that belongs to the package of the current
 > buffer, piping output from the program to the buffer and 
 > input from the buffer to the program."
 >   (interactive)
 >   (jde-junit-run-class (jde-junit-get-package-test-class)))
 > 
 > (defun jde-junit-get-package-test-class ()
 >   "Gets the package test class for the current buffer"
 >   (let ((package-test-class (concat (jde-db-get-package) "AllTests")))
 >     package-test-class))
 > 
 > 
 > I also have a function that enables quickly switching between a source
 > file and its corresponding test source file (I have it bound to a
 > key). This may be of less value depending on how (or whether) people
 > segregate their source files from their test source files (we have a
 > separate src and test hierarchy,
 > e.g. project/src/com/example/Blah.java and
 > project/test/com/example/BlahTest.java). (Experienced elisp people can
 > probably suggest a better method than my simple-replace-in-string
 > hackery.)
 > 
 > (defun jde-junit-swap-testsrc-file()
 >   "Swaps between source files in test and code hierarchies."
 >   (interactive)
 >   (find-file 
 >   (if (string-match "/src/" (buffer-file-name))
 >       (simple-replace-in-string (simple-replace-in-string (buffer-file-name) 
 > "/src/" "/test/") ".java$" "Test.java")
 >     (simple-replace-in-string (simple-replace-in-string (buffer-file-name) "/test/" 
 > "/src/") "Test.java$" ".java"))))
 > (defun simple-replace-in-string (str oldtext newtext)
 >   "Replace all matches in STR for OLDTEXT with NEWTEXT string,
 >  and returns the new string."
 >   (let ((index (string-match oldtext str)))
 >     (if index
 >         (concat (substring str 0 index)
 >                 newtext
 >                 (if (< (+ (length oldtext) index) (length str))
 >                     (substring str (+ (length oldtext) index))
 >                   ""))
 >       str)))
 > 
 > 
 > Hope you find these interesting.
 > 
 > Cheers,
 > Len.
 > 
 > ---------------------------------------------------------------------
 > To unsubscribe, e-mail: [EMAIL PROTECTED]
 > For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to