Announcement Announcement Module
Collapse
No announcement yet.
Junit tests are slow... Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Junit tests are slow...

    ...hey guys, I did a search and didn't see anything related to my question. I am interested in speeding up my Junit tests. I was originally running these tests on an older laptop. A Dell with a P2 and about 1.5gb of ram. I'm now running a new laptop with a 2.2ghz Celeron, and 4bg of RAM, and the speed of the Junit tests have not changed. Any ideas? Thanx...

  • #2
    Post your code... make sure you are using springs test framework, also not sure how this is related to web deve?!

    Comment


    • #3
      ...below is a sample of the tests I'm running. I'm assuming the two import statements for the springframework means I'm using springs test framework. I guess maybe I should have posted this in Spring Dev Tools forum...please feel free to move the post. Thanx!

      Code:
      /**
       * 
       */
      package com.digitalchalk.customer.test;
      
      import java.util.Random;
      
      import org.springframework.validation.BeanPropertyBindingResult;
      import org.springframework.validation.Errors;
      
      import com.digitalchalk.common.model.Message;
      import com.digitalchalk.core.util.DigitalChalkTests;
      import com.digitalchalk.customer.validator.MessageValidator;
      
      /**
       * @author Mark Locklear
       *
       */
      public class MessageValidatorTest extends DigitalChalkTests {
      	private MessageValidator messageValidator;
      	
      	public void setMessageValidator(MessageValidator messageValidator) {
      		this.messageValidator = messageValidator;
      	}
      	
      	public void testSupports() {
      		assertNotNull(messageValidator);
      		assertTrue(messageValidator.supports(Message.class));
      		assertFalse(messageValidator.supports(Object.class));
      		assertFalse(messageValidator.supports(javax.mail.Message.class));
      	}
      	
      	public void testValidateRequiredAndNull() {
      		Message message = new Message();
      		Errors errors = new BeanPropertyBindingResult(message, "message");
      		messageValidator.validate(message, errors);
      		assertTrue(errors.hasErrors());
      		assertTrue(errors.hasFieldErrors("subject"));
      		assertTrue(errors.hasFieldErrors("body"));
      		assertTrue(errors.hasFieldErrors("url"));
      		assertFalse(errors.hasFieldErrors("urlLabel"));
      	}
      	
      	public void testSubject() {
      		Message message = new Message();
      		
      		//tests empty char in subject field
      		String value1 = "";
      		message.setSubject(value1);
      		Errors errors1 = new BeanPropertyBindingResult(message, "message");
      		messageValidator.validate(message, errors1);
      		assertTrue(errors1.hasFieldErrors("subject"));
      			
      		//tests single char in subject field
      		String value2 = "Z";
      		message.setSubject(value2);
      		Errors errors2 = new BeanPropertyBindingResult(message, "message");
      		messageValidator.validate(message, errors2);
      		assertFalse(errors2.hasFieldErrors("subject"));
      
      		//tests 255 chars in subject field
      		String value3 = randomString(255);
      		message.setSubject(value3);
      		Errors errors3 = new BeanPropertyBindingResult(message, "message");
      		messageValidator.validate(message, errors3);
      		assertFalse(errors3.hasFieldErrors("subject"));
      		
      		//tests 256 chars in subject field
      		String value4 = randomString(256);
      		message.setSubject(value4);
      		Errors errors4 = new BeanPropertyBindingResult(message, "message");
      		messageValidator.validate(message, errors4);
      		assertTrue(errors4.hasFieldErrors("subject"));
      		
      		//tests space in subject field
      		String value5 = " ";
      		message.setSubject(value5);
      		Errors errors5 = new BeanPropertyBindingResult(message, "message");
      		messageValidator.validate(message, errors5);
      		assertTrue(errors5.hasFieldErrors("subject"));
      	}
      	
      	final String AB = " 0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ!@#$%^&*()_+{}][?><,./~`:;''";
      	Random rnd = new Random();
      
      	private String randomString( int len ) {
      	  StringBuilder sb = new StringBuilder( len );
      	  for( int i = 0; i < len; i++ ) {
      		  sb.append(AB.charAt(rnd.nextInt(AB.length() - 1)));
      	  }
      	  return sb.toString();
      	}
      
      }

      Comment


      • #4
        You aren't actuall using springs testing framework. You are using spring however.

        For starters why do you think/find it slow? You are using a BeanPropertyBindingResult which does use reflection, which slows things down, instead I suggest using a BindException instead. Also I would like to see what is going on in your DigitalChalkTests because currently I have no clue.

        Comment


        • #5
          For starters why do you think/find it slow?
          ...I was originally running these tests on an older laptop. A Dell with a P2 and about 1.5gb of ram. I'm now running a new laptop with a 2.2ghz Celeron, and 4bg of RAM, and the speed of the Junit tests have not changed. I'm new to Junit, so maybe running test shouldn't be any faster? Thats part of my question.

          You are using a BeanPropertyBindingResult which does use reflection, which slows things down, instead I suggest using a BindException instead.
          ...I'll try modifying a few tests to use BindException instead of BeanPropertyBindingResult and see if that helps performace...

          Comment


          • #6
            As stated without the full source/classes it is hard to determine what is happening and where you can get improvements. If they remain slow it either means your test is badly written or they are alread as fast as can be...

            Comment

            Working...
            X