
com.anarsoft.vmlens.concurrent.example.RaceConditionVolatileCounter Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of concurrent-junit Show documentation
Show all versions of concurrent-junit Show documentation
A http://junit.org test runner to run concurrent unit tests.
package com.anarsoft.vmlens.concurrent.example;
import static org.junit.Assert.assertEquals;
import org.junit.After;
import org.junit.Test;
import org.junit.runner.RunWith;
import com.anarsoft.vmlens.concurrent.junit.ConcurrentTestRunner;
/**
*
* Shows how to use org.junit.After annotation to check for the result of a computation.
* The assertion will fail when run with vmlens.com with
* "delay synchronization for unit tests" enabled.
*
*
*
* @author Thomas
*
*/
@RunWith(ConcurrentTestRunner.class)
public class RaceConditionVolatileCounter {
private volatile int i = 0;
@Test
public void addOne()
{
i++;
}
@After
public void assertCount()
{
assertEquals("4 Threads running addOne in parallel should lead to 4" , 4 , i);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy