当前位置: 首页 > 知识库问答 >
问题:

为什么@ignore annotation不忽略带注释的测试?

相威
2023-03-14
import java.math.BigInteger;
import java.util.UUID;
    
import org.fluttercode.datafactory.impl.DataFactory;
import org.junit.Ignore;
import org.junit.Test;
    
import junit.framework.TestCase;
    
public class AdapterAppTest extends TestCase {    
    @Ignore("this test is not ready yet")
        public static void testCreateApplicationWithAllRequiredParameters() {
            
            AdapterApp.setWsURL(URL);
        
            AdapterApp adapterApp = new AdapterApp(); 
            System.out.println("Set UP Request Parameters");
            
            DataFactory df = new DataFactory();
            
            adapterApp.setRequestTimestamp("2015-12-01T12:12:12.123"));
            adapterApp.setRequestUid(UUID.randomUUID().toString());
            adapterApp.setProductType("0");
            
            
            String applicationNum = adapterApp.createApplication();
            assertEquals("2 symb", 2, applicationNum.length());
        } 
}
<dependencies>
     

    <!-- Spring framework -->
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-context</artifactId>
        <version>4.2.3.RELEASE</version>
    </dependency>

    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-core</artifactId>
        <version>4.2.3.RELEASE</version>
    </dependency>


    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <version>4.12</version>
    </dependency>


    <dependency>
        <groupId>io.codearte.jfairy</groupId>
        <artifactId>jfairy</artifactId>
        <version>0.5.1</version>
    </dependency>


    <dependency>
        <groupId>org.fluttercode.datafactory</groupId>
        <artifactId>datafactory</artifactId>
        <version>0.8</version>
    </dependency>


    <dependency>
        <groupId>org.springframework.ws</groupId>
        <artifactId>spring-ws-core</artifactId>
        <version>2.2.3.RELEASE</version>
    </dependency>

    <dependency>
        <groupId>log4j</groupId>
        <artifactId>log4j</artifactId>
        <version>1.2.17</version>
    </dependency>

    <dependency>
        <groupId>org.apache.httpcomponents</groupId>
        <artifactId>httpclient</artifactId>
        <version>4.5.1</version>
    </dependency>



    <dependency>
        <groupId>xerces</groupId>
        <artifactId>xercesImpl</artifactId>
        <version>2.11.0</version>
    </dependency>



</dependencies>

<build>


    <plugins>


        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.3</version>
            <configuration>
                <source>${jdk.version}</source>
                <target>${jdk.version}</target>
                <encoding>UTF-8</encoding>
            </configuration>
        </plugin>


        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
            <version>2.19</version>
                <executions>
                <execution>
                    <goals>
                        <goal>test</goal>
                    </goals>
                </execution>
            </executions>
            
            
            <dependencies>
                <dependency>
                    <groupId>org.apache.maven.surefire</groupId>
                    <artifactId>surefire-junit47</artifactId>
                    <version>2.19</version>
                </dependency>
            </dependencies>
            
            <configuration>
                <includes>
                    <include>AdapterAppTest.java</include>
                </includes>
            </configuration>
        </plugin>




        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-jar-plugin</artifactId>
            <version>2.6</version>
            <configuration>
                <archive>
                    <manifest>
                        <mainClass>com.adapter</mainClass>
                    </manifest>
                </archive>
            </configuration>
        </plugin>



        <plugin>
            <artifactId>maven-assembly-plugin</artifactId>
            <configuration>
                <archive>
                    <manifest>
                        <mainClass>com.adapter</mainClass>
                    </manifest>
                </archive>
                <descriptorRefs>
                    <descriptorRef>jar-with-dependencies</descriptorRef>
                </descriptorRefs>
            </configuration>
        </plugin>


        <plugin>
            <groupId>org.jvnet.jaxb2.maven2</groupId>
            <artifactId>maven-jaxb2-plugin</artifactId>
            <version>0.13.0</version>
            <executions>
                <execution>
                    <goals>
                        <goal>generate</goal>
                    </goals>
                </execution>
            </executions>
            <configuration>
                <schemaLanguage>WSDL</schemaLanguage>
                <generatePackage>com.adapter_entities</generatePackage>
                <schemas>
                    <schema>
                        <url>src/main/resources/Import.wsdl</url>
                    </schema>
                </schemas>

            </configuration>
        </plugin>



    </plugins>
</build>
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building adapter 0.0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-jaxb2-plugin:0.13.0:generate (default) @ adapter ---
[INFO] Up-to-date check for source resources 
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ adapter ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 3 resources
[INFO] Copying 1 resource
[INFO]
[INFO] --- maven-compiler-plugin:3.3:compile (default-compile) @ adapter ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 25 source files to C:\Users\git\adapter\adapter\target\classes
[INFO]
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ adapter ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory C:\Users\git\adapter\adapter\src\test\resources
[INFO]
[INFO] --- maven-compiler-plugin:3.3:testCompile (default-testCompile) @ adapter ---
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] --- maven-surefire-plugin:2.19:test (default-test) @ adapter ---

-------------------------------------------------------
T E S T S
-------------------------------------------------------
Running com.adapter.AdapterAppTest

Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 3.546 sec - in com.adapter.AdapterAppTest

Results :

Tests run: 1, Failures: 0, Errors: 0, Skipped: 0

[INFO]
[INFO] --- maven-surefire-plugin:2.19:test (default) @ adapter ---
[INFO] Skipping execution of surefire because it has already been run for this configuration
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 12.452 s
[INFO] Finished at: 2015-12-03T16:09:13+03:00
[INFO] Final Memory: 25M/413M
[INFO] ------------------------------------------------------------------------

为什么@ignore注释无效?

共有1个答案

颜文昌
2023-03-14

您只展示了一小部分代码,但从我所看到的情况来看,我怀疑您使用的是JUnit3(从testcase扩展而来,并通过'test'前缀标识测试方法)。

ignore注释仅适用于JUnit4测试,即:

Testmethods使用@test进行注释,该类不是从TestCase继承的

public class AdapterAppTest {    
    @Test     
    @Ignore("this test is not ready yet")
    public static void testCreateApplicationWithAllRequiredParameters() {
 类似资料:
  • 问题内容: 我将Spring 3.1.3用于Web应用程序,将XML配置与组件扫描结合使用。 我意识到,其中一个扫描组件必须在其他几个组件之前进行初始化。在所有需要构造后初始化的类上,我在方法上具有@PostConstruct批注。 为了设置依赖关系顺序,我在需要先后构造的类上将“ @Component”更改为“ @Component(“ configData”)”。然后,在每个需要在“ conf

  • 根据我所读到的内容,这是我执行依赖顺序所需要的全部内容。 然后我构建了所有的东西,设置了我的断点,并启动了应用程序。我希望在任何依赖bean之前到达“configData”bean中的断点。事情不是这样的。第一个断点在一个依赖bean的“init”方法中。 然后我更改了“log4j.xml”,将“debug”设置为“org.springframework”的日志级别,并重新运行测试。断点行为是相同

  • 同时将warning的值设置为“all”或,没有任何结果。 checkstyle的文档很差。一些想法?

  • 我试图使用Jackson注释来重新命名序列化过程中产生的一些json标签。所有注释都编译得很好,当我运行时,除了所有Jackson注释之外,Jackson序列化工作完全被忽略。即使像@jsonignore或@jsonproperty这样的基本命令对json响应也没有影响。构建路径中的库有: 下面是我需要序列化的一个类的代码示例:

  • 有什么想法为什么@primary在这里没有被考虑在内吗?

  • 我对iOS布局约束的机制有误解。请参阅下面列出的我放在viewDidLoad中的代码。 在我看来,我的意图是明确的。我想在设备屏幕的中央看到一个按钮。但我只能看到下面的图片。 我在项目控制台中有一个输出,非常可怕,我无法从中理解任何东西。 无法同时满足约束。可能以下列表中至少有一个约束是您不想要的。尝试以下方法:(1)查看每个约束,并尝试找出您不期望的约束;(2) 查找添加了一个或多个不需要的约束