25.02.2015 Views

Introducing Spring Framework

Introducing Spring Framework

Introducing Spring Framework

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Chapter 7 ■ Testing Your <strong>Spring</strong> Application<br />

Description: Web Link<br />

Extension: .url<br />

2014-02-16 19:55:12,026 DEBUG [main] Start Params:<br />

2014-02-16 19:55:12,026 DEBUG [main] Start Params:<br />

2014-02-16 19:55:12,026 DEBUG [main] End Result:[Lcom.apress.isf.java.model.<br />

Document;@b29b889<br />

2014-02-16 19:55:12,027 DEBUG [main] End Result: [com.apress.isf.java.model.<br />

Document@60123018, com.apress.isf.java.model.Document@4a13a8ee, com.apress.isf.java.model.<br />

Document@50b7c740, com.apress.isf.java.model.Document@517a6426]<br />

2014-02-16 19:55:12,027 DEBUG [main] End Result: [com.apress.isf.java.model.<br />

Document@517a6426]<br />

2014-02-16 19:55:12,027 DEBUG [main] Start Params:<br />

2014-02-16 19:55:12,027 DEBUG [main] Start Params:<br />

2014-02-16 19:55:12,027 DEBUG [main] End Result:[Lcom.apress.isf.java.model.<br />

Document;@3a452494<br />

2014-02-16 19:55:12,027 DEBUG [main] End Result: [com.apress.isf.java.model.<br />

Document@60123018, com.apress.isf.java.model.Document@4a13a8ee, com.apress.isf.java.model.<br />

Document@50b7c740, com.apress.isf.java.model.Document@517a6426]<br />

2014-02-16 19:55:12,029 DEBUG [main] Using <strong>Spring</strong> Test fixtures on Unix:<br />

The two tests run because the correct value is returned in each.<br />

■ ■Note If you removed the @ProfileValueSourceConfiguration, then the unit test will be based on the<br />

System.getProperty(propertyKey). This means that if you add the Environment variable os.name with value Unix,<br />

then the test method testUsing<strong>Spring</strong>TestWithCustomProfilesY will be executed.<br />

More Test Annotations<br />

The <strong>Spring</strong> <strong>Framework</strong> provides even more annotations to test with. Let’s see some examples. Listing 7-8 shows<br />

the @Timed and @Repeat annotations that can be used only when using the <strong>Spring</strong>JUnit4ClassRunner or JUnit<br />

support classes.<br />

Listing 7-8. MyDocumentsMoreAnnotationsTest.java (@Timed, @Repeat)<br />

package com.apress.isf.spring.test;<br />

import static org.junit.Assert.assertEquals;<br />

import static org.junit.Assert.assertNotNull;<br />

import static org.junit.Assert.assertTrue;<br />

import java.util.List;<br />

import org.junit.Test;<br />

import org.junit.runner.RunWith;<br />

import org.slf4j.Logger;<br />

import org.slf4j.LoggerFactory;<br />

import org.springframework.beans.factory.annotation.Autowired;<br />

83

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!