Skip to content

Commit 9ee0ee2

Browse files
committed
JUnit tests
1 parent 19c5a99 commit 9ee0ee2

File tree

6 files changed

+124
-21
lines changed

6 files changed

+124
-21
lines changed

ReadMe.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,11 @@ These are the steps:
1717
6. Using a SplitLayoutPanel
1818
7. Internationalisation
1919
8. Hibernate and H2 (keeping MyBatis and SQLite in the configuration)
20+
9. JUnit tests
2021

2122
Next steps:
2223

23-
10. Unit tests
24+
10. GWT unit tests
2425
11. Use of GXT
2526

2627
# Run the application
@@ -68,6 +69,8 @@ Click on `Run project` or type F6.
6869

6970
- `mvn compile` only compiles Java sources.
7071
- `mvn gwt:compile` only compiles GWT module and writes extras.
72+
- `mvn test` run JUnit tests.
73+
- `mvn gwt:test` run GWT unit tests.
7174

7275
## In NetBeans
7376

@@ -76,6 +79,9 @@ Click on `Run project` or type F6.
7679
3. In the project custom menu, click on `Run GWT code server`.
7780
4. Visit the url said by the code server to install the bookmarklet.
7881

82+
- To run JUnit tests, in the project menu, click on `Test`.
83+
- To run GWT unit tests, in the project custom menu, click on `Run GWT unit tests`.
84+
7985
# License
8086

8187
The source code is licensed under [Apache License 2.0](http://www.apache.org/licenses/LICENSE-2.0).

nbactions.xml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,11 @@
1717
<runTarget>hellogwt/</runTarget>
1818
</properties>
1919
</action>
20+
<action>
21+
<actionName>CUSTOM-Run GWT unit tests</actionName>
22+
<displayName>Run GWT unit tests</displayName>
23+
<goals>
24+
<goal>gwt:test</goal>
25+
</goals>
26+
</action>
2027
</actions>

pom.xml

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,15 @@ Now, we add GWT (gwt-servlet and gwt-user artifacts) and Log4J to our project.
129129
<groupId>com.h2database</groupId>
130130
<artifactId>h2</artifactId>
131131
<version>${h2.version}</version>
132-
</dependency>
132+
</dependency>
133+
134+
<!-- Testing -->
135+
<dependency>
136+
<groupId>junit</groupId>
137+
<artifactId>junit</artifactId>
138+
<version>4.11</version>
139+
<scope>test</scope>
140+
</dependency>
133141
</dependencies>
134142

135143
<build>
@@ -171,9 +179,17 @@ Now, we add GWT (gwt-servlet and gwt-user artifacts) and Log4J to our project.
171179
</i18nConstantsBundles>
172180
<i18nMessagesBundle>com.hellogwt.client.i18n.ClientMessages</i18nMessagesBundle>
173181
<!--
182+
Unit tests:
183+
Default naming convention of the Maven GWT plugin :
184+
*Test.java for standard unit tests and
185+
GwtTest*.java for GWT test cases.
174186
-->
187+
<!-- Run tests using HtmlUnit -->
188+
<mode>htmlunit</mode>
175189
</configuration>
176190
</plugin>
191+
192+
<!-- Tomcat deployment -->
177193
<!-- $HOME/.m2/settings.xml
178194
<settings>
179195
<servers>
@@ -196,6 +212,7 @@ Now, we add GWT (gwt-servlet and gwt-user artifacts) and Log4J to our project.
196212
<path>/hellogwt</path>
197213
</configuration>
198214
</plugin>
215+
199216
<!--
200217
download-maven-plugin is used to download and cache other files
201218
-->

src/main/webapp/WEB-INF/log4j.xml

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,23 @@
11
<?xml version="1.0" encoding="UTF-8" ?>
22
<!DOCTYPE log4j:configuration SYSTEM "http://logging.apache.org/log4j/1.2/apidocs/org/apache/log4j/xml/doc-files/log4j.dtd">
33
<log4j:configuration debug="true"
4-
xmlns:log4j='http://jakarta.apache.org/log4j/'>
5-
6-
<appender name="file" class="org.apache.log4j.RollingFileAppender">
7-
<param name="append" value="false" />
8-
<param name="maxFileSize" value="10KB" />
9-
<param name="maxBackupIndex" value="5" />
10-
<!-- For Tomcat -->
11-
<param name="file" value="${catalina.home}/logs/hellogwt.log" />
12-
<layout class="org.apache.log4j.PatternLayout">
13-
<param name="ConversionPattern"
14-
value="%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n" />
15-
</layout>
16-
</appender>
17-
18-
<root>
19-
<level value="ERROR" />
20-
<appender-ref ref="file" />
21-
</root>
22-
4+
xmlns:log4j='http://jakarta.apache.org/log4j/'>
5+
6+
<appender name="file" class="org.apache.log4j.RollingFileAppender">
7+
<param name="append" value="false" />
8+
<param name="maxFileSize" value="10KB" />
9+
<param name="maxBackupIndex" value="5" />
10+
<!-- For Tomcat -->
11+
<param name="file" value="${catalina.home}/logs/hellogwt.log" />
12+
<layout class="org.apache.log4j.PatternLayout">
13+
<param name="ConversionPattern"
14+
value="%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n" />
15+
</layout>
16+
</appender>
17+
18+
<root>
19+
<level value="ERROR" />
20+
<appender-ref ref="file" />
21+
</root>
22+
2323
</log4j:configuration>

src/test/java/SimpleJUnitTest.java

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
/**
2+
* Simple sample of JUnit4 test.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
import org.junit.After;
18+
import org.junit.AfterClass;
19+
import static org.junit.Assert.assertTrue;
20+
import org.junit.Before;
21+
import org.junit.BeforeClass;
22+
import org.junit.Test;
23+
24+
/**
25+
*
26+
* @author Olivier Maury <Olivier.Maury@paca.inra.fr>
27+
*/
28+
public class SimpleJUnitTest {
29+
30+
public SimpleJUnitTest() {
31+
}
32+
33+
@BeforeClass
34+
public static void setUpClass() {
35+
}
36+
37+
@AfterClass
38+
public static void tearDownClass() {
39+
}
40+
41+
@Before
42+
public void setUp() {
43+
}
44+
45+
@After
46+
public void tearDown() {
47+
}
48+
49+
/**
50+
* The methods must be annotated with annotation @Test.
51+
*/
52+
@Test
53+
public void simple() {
54+
assertTrue(true);
55+
}
56+
}

src/test/resources/log4j.xml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?xml version="1.0" encoding="UTF-8" ?>
2+
<!DOCTYPE log4j:configuration SYSTEM "http://logging.apache.org/log4j/1.2/apidocs/org/apache/log4j/xml/doc-files/log4j.dtd">
3+
<log4j:configuration debug="true"
4+
xmlns:log4j='http://jakarta.apache.org/log4j/'>
5+
6+
<appender name="console" class="org.apache.log4j.ConsoleAppender">
7+
<layout class="org.apache.log4j.PatternLayout">
8+
<param name="ConversionPattern" value="[%d] - [%t] %-5p | %c#%M() | %F:%L - %m%n" />
9+
</layout>
10+
</appender>
11+
12+
<root>
13+
<level value="ERROR" />
14+
<appender-ref ref="console" />
15+
</root>
16+
17+
</log4j:configuration>

0 commit comments

Comments
 (0)