Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You are reusing your context, in order to have tests independent from one another you probably need to refresh your context after each test to reset everything.</p> <p>I will suppose you are using Junit 4.5+. It would be similar with other test frameworks. </p> <pre><code>@RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration(locations={"mycontext.xml"}) @DirtiesContext(classMode = ClassMode.AFTER_EACH_TEST_METHOD) public class MyTestClass { ... // my tests ... } </code></pre> <p>You can put the <code>@DirtiesContext</code> at the method level if the methods that need "fixing" are few, but if you are using Spring your best option is to do it after every test.</p> <p>Anyway, I don't think you should be using mocks/spies in integration tests:</p> <ul> <li><p>In unit tests, use mocks (if you want) and inject manually. Here you want to verify the behaviour of your tested bean as a unit, so you isolate it from the rest by using mocks. This also has the advantage that JUnit isolates your tests by using a different instance of the test class for each test, so unless you use <code>static</code> or other test-unfriendly practices everything will just work.</p></li> <li><p>In integration tests, use real beans and let Spring inject. Here the goal is to verify that beans interact well with one another / with the environment (database, network, ...) You do <em>not</em> want to isolate beans here, so you should not use mocks.</p></li> </ul> <p>See <a href="http://static.springsource.org/spring/docs/3.0.0.RELEASE/reference/html/testing.html#testcontext-support-classes" rel="noreferrer">Spring documentation about testing</a> for more detailed explanations.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload