Changes for page Testing-JUnit and TestNG
Last modified by Johann Werner on 2012/08/06 03:19
From version 8.1
edited by Greg.Brown
on 2009/09/26 11:59
on 2009/09/26 11:59
Change comment:
There is no comment for this version
Summary
-
Page properties (2 modified, 0 added, 0 removed)
Details
- Page properties
-
- Author
-
... ... @@ -1,1 +1,1 @@ 1 -XWiki. gbrown1 +XWiki.kiddyr - Content
-
... ... @@ -1,5 +1,57 @@ 1 -= Testing with JUnit and the similar TestNG =1 += Testing with JUnit or TestNG = 2 2 3 +== Various approaches to initializing your application for testing == 4 + 5 +For unit type tests, initialization isn't usually a problem, as unit testing only tests a small "unit" isolated and not interacting with all the other "units" which make up your application. But there are other tests which may require many units of your application working cooperatively, and in order to work properly, all these units must be initialized properly. 6 + 7 +=== Create a method which runs once before any tests === 8 + 9 +Your application should be initialzed just once before the tests. There are annotations etc. which allow one to pick a method which will be run prior to any tests. For a TestNG example (similar to Junit 4): 10 + 11 +{{code}} 12 + 13 +package example.com.test; 14 + 15 +import er.extensions.appserver.ERXApplication; 16 +import java.util.Properties; 17 + 18 +import org.testng.annotations.BeforeTest; 19 + 20 +import com.webobjects.appserver.WOApplication; 21 +import com.webobjects.foundation.NSBundle; 22 + 23 +public class WOInit { 24 + static NSBundle MYBUNDLE = NSBundle.mainBundle(); 25 + 26 + @BeforeTest // init once 27 + public void initWO() { 28 + 29 + System.out.println("****InitWO starting...mainbundle is " + NSBundle.mainBundle().bundlePath()); 30 + // somehow 'new' seems to init the static structures best 31 + example.com.app.Application myApp = new example.com.app.Application( ) ; 32 + //ERXApplication.primeApplication(NSBundle.mainBundle().bundlePath(), null, "example.com.app.Application"); 33 + //er.extensions.ERXExtensions.initApp(example.com.app.Application.class, new String[0]) ; 34 + System.out.println("****InitWO lists mainbundle:"); 35 + MYBUNDLE.properties().list(System.out); 36 + Properties props = System.getProperties(); 37 + System.out.println(props.toString()); 38 + System.out.println("****InitWO ...Finished... "); 39 + 40 + } 41 + 42 +} 43 + 44 +{{/code}} 45 + 46 +There are various ways (some commented out) to initialize your application in the above example. 47 + 48 +* example.com.app.Application myApp = new example.com.app.Application( ) ; 49 +* ERXApplication.primeApplication(NSBundle.mainBundle().bundlePath(), null, "example.com.app.Application"); ~/~/(Wonder) or 50 +* WOApplication.primeApplication(NSBundle.mainBundle().bundlePath(), null, "example.com.app.Application"); ~/~/(No Wonder) 51 +* er.extensions.ERXExtensions.initApp(example.com.app.Application.class, new StringWO:0) ; 52 + 53 +One of them may work best in your situation. It may be important for your application to find its main bundle properly, and all the goodies bound up in that main bundle. 54 + 3 3 == Minor configuration in eclipse == 4 4 5 5 To be able to test your business objects layer in JUnit test cases, you should set the following parameters in your test case/test suite launch configuration : ... ... @@ -7,7 +7,7 @@ 7 7 8 8 {{noformat}} 9 9 10 -${workspace_loc:MyEclipseProject/build/MyEclipseProject.framework} 62 +${workspace_loc:MyEclipseProject/build/MyEclipseProject.framework} 11 11 12 12 {{/noformat}} 13 13