• Post Reply Bookmark Topic Watch Topic
  • New Topic

How should I test GUIs using Eclipse?  RSS feed

 
Matthew Busse
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello everyone,

I'm learning how to use eclipse for Java programming. I want to make a GUI, and I'm trying to follow test-driven development, so I wrote a method to test a method that builds a GUI. Then I wrote a method to build a simple GUI. When I run the test method, should it actually make the GUI so I can look at it? Right now, it looks like the GUI flashes up for a second, then disappears.

I tried to post this question on the Eclipse forum, but that website is so slow, I had difficulty loading any of the pages.

Here's the code of the test method:


And here's the code of the GUI:



Is there a way I can look at the GUI with the test method in eclipse, or should I writing a main method and compile and run the class from the command line?

Thanks,

Matt
 
Hunter McMillen
Ranch Hand
Posts: 492
Firefox Browser Linux VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
you don't have an entry point into your application. If you want to see your GUI I believe you either need to have a main method, or extend JApplet, and place the start-up code in the init() method.

Hunter
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24217
38
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hunter McMillen wrote:you don't have an entry point into your application.


This is a JUnit test case -- the method marked @Test will be invoked by the test framework. It's all good.

Matthew Busse wrote:should I writing a main method and compile and run the class from the command line


Yes, if you want to have a look at your GUI, it's be better to create a main() method and run it as an application.

I commend you for doing test-driven development, but I'll point out that the "tests" in test-driven development are supposed to be automated tests that run with no human intervention. You absolutely can write JUnit tests for GUIs, but the tests should use the assertX() methods in JUnit to actually examine the GUI automatically, and they shouldn't rely on you being present to look at anything.
 
Matthew Busse
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ernest Friedman-Hill wrote:
I commend you for doing test-driven development, but I'll point out that the "tests" in test-driven development are supposed to be automated tests that run with no human intervention. You absolutely can write JUnit tests for GUIs, but the tests should use the assertX() methods in JUnit to actually examine the GUI automatically, and they shouldn't rely on you being present to look at anything.


Thank you for pointing that out. I've worked through several of the eclipse tutorials, and although the tests are set up to be automated, they never actually explain why. That explains why when I googled "Test GUI in Eclipse", most of the links were about automated testing of GUIs.

Now maybe you can help me, I've really screwed something up. I wrote a main method, but now eclipse is giving me this error:
The project was not built due to "Could not delete '/multiBLAST/bin/com'.". Fix the problem, then try refreshing this project and building it since it may be inconsistent



Here's the program:



Something really strange is going on. I tried to just run the FileChooser.class file from the command line, and I kept getting the error that it couldn't find the main class. I thought maybe Eclipse hadn't recompiled the file after I wrote the main method, so I selected Project -> Clean, because I thought that would recompile everything, and that's when eclipse started giving me the error above.

I'm in over my head here, any assistance would be greatly appreciated.
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24217
38
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"Can't delete directory" messages on Windows are virtually always due to a program having the directory as its current working directory, or a file in the directory open. So either a command window is open with that directory as its current directory, or you've got one of the files open in WordPad or something. A silly but effective way of clearing the problem without figuring out the exact cause would be to reboot the computer!
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!