How can performed method setUp only once in tests

Paushchyk Julia

I have test:

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes = {TestRepositoryConfig.class})
@Transactional
public class ServiceTest {

    @Autowired
    private UserRepository userRepository;

    @Autowired
    private Service service;

static {
   initTestUser();
}

public void setUp() { 
   userRepository.seve(testUser);
}

public void test1() { ... }

public void test2() { ... }

I need first start method setUp, saving testUser, then start methods test1 and test2. Method setUp must performed only once! How can do it?

Ayzen

I believe the problem you are trying to solve should be done in a different way. As far as I see you want to fill your DB with some test data, and this is better to do in a global configuration for all tests.

But if you want to stick to your initial idea you can try an approach with listeners described in this blog post.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

How to define a setup method only called once during testing with nosetest?

running setup method for junit only once

Have setup method run only once

Loop the deserialization is performed only once

How can I execute a method only once in Vue?

How can I call a method inside Update only once?

How can I run cleanup method only after tagged tests?

installed NSSM service is only performed once

How to extract people who have only performed an activity once from a table

What kind of espresso tests can be performed on a recyclerView

How can I make sure a method is only called once by multiple threads?

How can I get mock a method to only return an object once? (I am testing a pagination cursor)

How to setup database connections only once from startup in .NET Core?

Airflow Scheduling: how to run initial setup task only once?

Google Test: How to run fixture only once for multiple tests?

How to use monkeypatch in a "setup" method for unit tests using pytest?

How can I execute a function only once?

How can I zoom only for once?

Livewire flash message appears only once when action if performed

Mock a method only once

splice method only once

How can I stub in setup method with Minitest?

How can I write tests that have setup and teardown operations that are asynchronous?

TestNG - How to run setup once before all tests in a class for each parallel run

Workng Google Maps API I have it setup so that the user can add a selection rectangle to their screen. How can I only do this just once?

When using JUnit's @Parameterized, can I have some tests still run only once

How to trigger a vue method only once, not every time

How to run singleton method only once in multiple test projects

How to make OnControllerColliderHit method to detect collision only once?