mirror of
https://github.com/sigmasternchen/xtext-core
synced 2025-03-16 00:38:56 +00:00
Merge pull request #298 from eclipse/lb_flaky-tests
Added tests for .xtext.testing.Flaky
This commit is contained in:
commit
917944c0f7
3 changed files with 138 additions and 0 deletions
|
@ -0,0 +1,54 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2014 itemis AG (http://www.itemis.eu) and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*******************************************************************************/
|
||||
package org.eclipse.xtext.testing.tests;
|
||||
|
||||
import org.eclipse.xtext.testing.Flaky;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.TestRule;
|
||||
import org.junit.runner.Description;
|
||||
import org.junit.runners.model.Statement;
|
||||
|
||||
/**
|
||||
* @author Sebastian Zarnekow
|
||||
*/
|
||||
public class FlakyFailsFourTimes {
|
||||
@Rule
|
||||
public Flaky.Rule rule = new Flaky.Rule();
|
||||
|
||||
@Rule
|
||||
public TestRule verifier = new TestRule() {
|
||||
|
||||
public Statement apply(final Statement base, Description description) {
|
||||
return new Statement() {
|
||||
|
||||
@Override
|
||||
public void evaluate() throws Throwable {
|
||||
try {
|
||||
base.evaluate();
|
||||
Assert.fail("Expected exception");
|
||||
} catch(IllegalStateException e) {
|
||||
// expected
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
static int fails = 4;
|
||||
|
||||
@Test
|
||||
@Flaky
|
||||
public void flakyTest() {
|
||||
fails--;
|
||||
if (fails > 0) {
|
||||
throw new IllegalStateException();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,30 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2014 itemis AG (http://www.itemis.eu) and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*******************************************************************************/
|
||||
package org.eclipse.xtext.testing.tests;
|
||||
|
||||
import org.eclipse.xtext.testing.Flaky;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* @author Sebastian Zarnekow
|
||||
*/
|
||||
public class FlakyFailsTwoTimes {
|
||||
@Rule
|
||||
public Flaky.Rule rule = new Flaky.Rule();
|
||||
|
||||
static int fails = 2;
|
||||
|
||||
@Test
|
||||
@Flaky
|
||||
public void flakyTest() {
|
||||
fails--;
|
||||
Assert.assertTrue(fails <= 0);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,54 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2014 itemis AG (http://www.itemis.eu) and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*******************************************************************************/
|
||||
package org.eclipse.xtext.testing.tests;
|
||||
|
||||
import org.eclipse.xtext.testing.Flaky;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.TestRule;
|
||||
import org.junit.runner.Description;
|
||||
import org.junit.runners.model.Statement;
|
||||
|
||||
/**
|
||||
* @author Sebastian Zarnekow
|
||||
*/
|
||||
public class IllegalFlakyConfigTest {
|
||||
|
||||
@Rule
|
||||
public Flaky.Rule rule = new Flaky.Rule();
|
||||
|
||||
@Rule
|
||||
public TestRule verifier = new TestRule() {
|
||||
|
||||
public Statement apply(final Statement base, Description description) {
|
||||
return new Statement() {
|
||||
|
||||
@Override
|
||||
public void evaluate() throws Throwable {
|
||||
try {
|
||||
base.evaluate();
|
||||
Assert.fail("Expected exception");
|
||||
} catch(IllegalArgumentException expected) {
|
||||
// ok
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
@Test
|
||||
@Flaky(trials = 1)
|
||||
public void testIllegalNumberOfTrials_01() {}
|
||||
|
||||
@Test
|
||||
@Flaky(trials = 101)
|
||||
public void testIllegalNumberOfTrials_02() {}
|
||||
|
||||
}
|
Loading…
Reference in a new issue