简体   繁体   中英

How do I create pre-formatted Java files in Eclipse?

I am currently writing JUnit test cases using the Selenium-RC API. I am writing my scripts like:

//example JUnit test case

public class myScripts extends SeleneseTestCase {

   public void setUp() throws Exception {
      SeleniumServer newSelServ = new SeleniumServer();
      newSelServ.start();
      setUp("https://mySite.com", "*firefox");
   }

   public void insert_Test_Name throws Exception {

       //write test code here

   }
}

And for each test, I have a new JUnit file. Now, since the beginning of my JUnit files will all basically be the same, just with minor variations towards the end, I was thinking about creating a pre-formatted Java template to write create a file with the redundant code already written. However, I can't find any information on whether this is possible. Does Eclipse allow you to create file templates for certain packages?

Create a super class to add all the common code. Creating template is really bad because of the fact you are duplicating the code at the end of the day.

class Super extends SeleneseTestCase{
// Add all common code
}

class Test1 extends Super{
   // only special test case logic

}

Also I would suggest not to create SeleniumServer instance for each test case, It will reduce overall performance of the test suite. You can reuse object as long as you are running test sequentially.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM