|
Spring Framework example source code file (EnabledAndIgnoredSpringRunnerTests.java)
The Spring Framework EnabledAndIgnoredSpringRunnerTests.java source code
/*
* Copyright 2002-2007 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.test.context.junit4;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.test.annotation.IfProfileValue;
import org.springframework.test.annotation.ProfileValueSource;
import org.springframework.test.annotation.ProfileValueSourceConfiguration;
import org.springframework.test.context.TestExecutionListeners;
/**
* <p>
* Verifies proper handling of JUnit's {@link org.junit.Ignore @Ignore} and
* Spring's
* {@link org.springframework.test.annotation.IfProfileValue @IfProfileValue}
* and {@link ProfileValueSourceConfiguration @ProfileValueSourceConfiguration}
* (with the <em>implicit, default {@link ProfileValueSource})
* annotations in conjunction with the {@link SpringJUnit4ClassRunner}.
* </p>
* <p>
* Note that {@link TestExecutionListeners @TestExecutionListeners} is
* explicitly configured with an empty list, thus disabling all default
* listeners.
* </p>
*
* @author Sam Brannen
* @since 2.5
* @see HardCodedProfileValueSourceSpringRunnerTests
*/
@RunWith(SpringJUnit4ClassRunner.class)
@TestExecutionListeners( {})
public class EnabledAndIgnoredSpringRunnerTests {
protected static final String NAME = "EnabledAndIgnoredSpringRunnerTests.profile_value.name";
protected static final String VALUE = "enigma";
protected static int numTestsExecuted = 0;
@BeforeClass
public static void setProfileValue() {
numTestsExecuted = 0;
System.setProperty(NAME, VALUE);
}
@AfterClass
public static void verifyNumTestsExecuted() {
assertEquals("Verifying the number of tests executed.", 3, numTestsExecuted);
}
@Test
@IfProfileValue(name = NAME, value = VALUE + "X")
public void testIfProfileValueDisabled() {
numTestsExecuted++;
fail("The body of a disabled test should never be executed!");
}
@Test
@IfProfileValue(name = NAME, value = VALUE)
public void testIfProfileValueEnabledViaSingleValue() {
numTestsExecuted++;
}
@Test
@IfProfileValue(name = NAME, values = { "foo", VALUE, "bar" })
public void testIfProfileValueEnabledViaMultipleValues() {
numTestsExecuted++;
}
@Test
public void testIfProfileValueNotConfigured() {
numTestsExecuted++;
}
@Test
@Ignore
public void testJUnitIgnoreAnnotation() {
numTestsExecuted++;
fail("The body of an ignored test should never be executed!");
}
}
Other Spring Framework examples (source code examples)Here is a short list of links related to this Spring Framework EnabledAndIgnoredSpringRunnerTests.java source code file: |
| ... this post is sponsored by my books ... | |
#1 New Release! |
FP Best Seller |
Copyright 1998-2024 Alvin Alexander, alvinalexander.com
All Rights Reserved.
A percentage of advertising revenue from
pages under the /java/jwarehouse
URI on this website is
paid back to open source projects.