DEV Community

Query Filter
Query Filter

Posted on

exec-11


// For Junit5 conflicting tests  are resolved using a ResourceLock

import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.parallel.ResourceLock;
import org.junit.jupiter.api.parallel.Resources;

class LegacyServiceTest {

    @Test
    @ResourceLock("SHARED_CONFIG_FILE") // Use any unique string key
    void testFirstConflictingOperation() {
        // Modifies shared file/state
    }

    @Test
    @ResourceLock("SHARED_CONFIG_FILE") // Matches the key above
    void testSecondConflictingOperation() {
        // Reads/Modifies same shared file/state
    }
}

// For Junit4 use name ordering

Java
import org.junit.Test;
import org.junit.FixMethodOrder;
import org.junit.runners.MethodSorters;

@FixMethodOrder(MethodSorters.NAME_ASCENDING)
public class LegacyIntegrationTest {

    @Test
    public void test01_firstOperation() {
        // Executes first alphabetically
    }

    @Test
    public void test02_secondOperation() {
        // Executes second alphabetically
    }
}
Enter fullscreen mode Exit fullscreen mode

Top comments (0)