Edmund Wong

+ Follow
since Jul 18, 2012
Cows and Likes
Total received
In last 30 days
Total given
Total received
Received in last 30 days
Total given
Given in last 30 days
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Edmund Wong


I've created my very first HelloWorld app that opens a panel with Hello World in it, as follows:

It's not much I know as it's pretty much a copy and paste from http://www.vogella.com/articles/SWT/article.html,
with some minor changes. How would I 'unit test' this Hello World app out?

Now I've heard there's Swing, AWT and SWT. I just used SWT. Which should I use for GUI applications?

Also, and probably related, I was wondering with regards to building complex applications (like ERPs, etc), is there an easier way
of doing this other than creating each widget on the display one widget at a time? I'm sorry if this sounds like a stupid
(and probably impatient) question.

Thanks for your help and clarifications.


8 years ago

Jesper de Jong wrote:The actual output is "Hello World!" with a newline character appended to it; you expect that it is "Hello World!" without a newline character appended.

Either try this in line 24:

Or, in line 9, use print() instead of println(). Note that println() prints the text you specify plus a newline.

Oooh. I understand now. Thanks.

Jesper de Jong wrote:
Are you using JUnit? Normally you would not have a main() method in your JUnit test. You'd just write a test method with a @Test annotation above it, and then use JUnit from Eclipse to run the test (Run -> Run As... -> JUnit Test).

So, instead of a main() method in class HelloWorldTest, you'd have something like this:

Yes, I'm using JUnit, but I have no idea how to use it properly. Thanks for the help on that though.

8 years ago

I'm new here, plus I'm new to Java and Eclipse, which is what I'm using to do java programming.

Given this:

Why do I get the following assertion error?

Exception in thread "main" org.junit.ComparisonFailure: expected:<Hello World![]> but was:<Hello World![
at org.junit.Assert.assertEquals(Assert.java:125)
at org.junit.Assert.assertEquals(Assert.java:147)
at HelloWorldTest.main(HelloWorldTest.java:24)

I got this part:

final ByteArrayOutputStream outContent = new ByteArrayOutputStream();

System.setOut(new PrintStream(outContent));

from googling on how to compare what is printed out from "System.out.println" with
an expected string. (I'm c&p from the output window.. I'm noticing that the
"but was:.." part has an extra \n between the []. Is this normal?

Am I doing something wrong?

Any help appreciated.

8 years ago