Przeglądaj źródła

Added template information for running unit tests.

Thomas Flucke 7 lat temu
rodzic
commit
0fcd4bf316

+ 15 - 7
build.xml

@@ -16,12 +16,14 @@
 
   <property prefix="build" file="${ant.conf.dir}/build.properties"/>
   <property name="build.lib" value="${lib.dir}/war/"/>
-  <property name="build.warfile" value="${build.dir}/${app.name}-${build.version}.war"/>
+  <property name="build.warfile"
+            value="${build.dir}/${app.name}-${build.version}.war"/>
   <tstamp>
 	<format property="build.time" pattern="MM/dd/yyyy hh:mm aa z" />
   </tstamp>
 
-  <property name="test.failure.halt" value="no"/>
+  <property name="test.halt.failure" value="off"/>
+  <property name="test.halt.error" value="off"/>
   <property name="test.lib" value="${lib.dir}/test/"/>
   <property name="test.target.dir" value="${build.dir}/tests"/>
 
@@ -139,7 +141,8 @@
 	</javac>
   </target>
   
-  <target name="war" depends="compile.server,ivy.resolve.war" description="Create application WAR">
+  <target name="war" depends="compile.server,ivy.resolve.war"
+          description="Create application WAR">
 	<mkdir dir="${build.dir}"/>
 	<war warfile="${build.warfile}" webxml="${app.conf.dir}/web.xml">
       <lib dir="${build.lib}"/>
@@ -154,16 +157,21 @@
   <target name="test.server"
           description="Run all unit tests on server"
           depends="compile.server,compile.tests,test.load">
-    <junit printsummary="yes" haltonfailure="${test.failure.halt}">
+    <junit printsummary="yes"
+           haltonfailure="${test.halt.failure}"
+           haltonerror="${test.halt.error}">
       <classpath>
-	    <fileset dir="${test.lib}" includes="*.jar"/>
-        <path refid="compile.classpath"/>
+	    <path refid="compile.classpath"/>
+        <fileset dir="${test.lib}" includes="*.jar"/>
+        <fileset dir="${lib.dir" includes="*.jar"/>
         <pathelement location="${test.target.dir}"/>
+        <pathelement location="conf/test/app/"/>
       </classpath>
       <batchtest fork="yes">
-        <fileset dir="${test.target.dir}">
+        <fileset dir="${test.dir}">
           <include name="**/*.java"/>
         </fileset>
+        <formatter type="plain" usefile="false"/>
       </batchtest>
     </junit>
   </target>

+ 12 - 0
conf/test/app/application.properties

@@ -0,0 +1,12 @@
+# TODO: Integrate these into JSP where appropriate
+
+# ieat app
+app.url=localhost:8080/ieat-2.0.0
+
+# logging
+# TODO: figured out why logging level throws errors.
+#logging.level.*=error
+#logging.config=log4j.properties
+#log4j.appender.file.File=${log.file.path}/${project.artifactId}.log
+
+ndb.api.key=CfiHcUnSf0RX0jBuqiWjDK2d2ziOmoZG15CTdhQn

+ 5 - 0
conf/test/app/db.properties

@@ -0,0 +1,5 @@
+# DB Properties
+
+spring.data.mongodb.host=localhost
+spring.data.mongodb.port=27017
+spring.data.mongodb.database=ieat

+ 2 - 0
conf/test/app/jsp.properties

@@ -0,0 +1,2 @@
+url=http://localhost:8080/ieat-2.0.0
+ndbKey=CfiHcUnSf0RX0jBuqiWjDK2d2ziOmoZG15CTdhQn

+ 4 - 0
conf/test/app/web.properties

@@ -0,0 +1,4 @@
+# web resources
+
+# Timeout in seconds
+web.resources.timeout = 0

+ 38 - 0
tests/name/tflucke/ieat2/controllers/FoodControllerTest.java

@@ -0,0 +1,38 @@
+package name.tflucke.ieat2.controllers;
+
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.test.context.ContextConfiguration;
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
+import org.springframework.test.context.web.WebAppConfiguration;
+
+import name.tflucke.ieat2.configs.RootConfig;
+import name.tflucke.ieat2.configs.DBConfig;
+
+import static org.junit.Assert.assertTrue;
+
+@SpringBootTest
+@RunWith(SpringJUnit4ClassRunner.class)
+@ContextConfiguration(classes = {DBConfig.class, FoodController.class})
+public class FoodControllerTest {
+ 
+    @Autowired
+    private FoodController controller;
+  
+    @Test
+    public void fail() {
+        assertTrue(false);
+    }
+  
+    @Test
+    public void pass() {
+        assertTrue(true);
+    }
+  
+    @Test
+    public void isDefined() {
+        assertTrue(controller != null);
+    }
+}