AntとTestNGタスクの例

AntおよびTestNGタスクの例

testng tutorials

このチュートリアルでは、AntビルドでTestNGテストを実行する方法を示します。

1. クラスで実行

build.xml

  
    
  

  

    
    

        
        
        
        

        
        

    

  

2. XMLで実行

$\{resources.dir}/testng.xml




    
    
        
    
    

build.xml

  
    
  

  

    

        

        
        

    

  

3. 例

TestNGテストのセットを実行する方法を示すWebアプリケーションの例。

3.1 Return a message

MessageGenerator.java

package com.example.message;

import org.springframework.stereotype.Component;

@Component
public class MessageGenerator {

    public String getWelcomeMessage() {
        return "welcome";
    }

}

3.2 Two TestNG tests.

TestMessage.java

package com.example.test;

import org.testng.Assert;
import org.testng.annotations.Test;
import com.example.message.MessageGenerator;

public class TestMessage {

    @Test
    public void test_welcome_message() {
        MessageGenerator obj = new MessageGenerator();
        Assert.assertEquals(obj.getWelcomeMessage(), "welcome");
    }

}

TestMessage2.java

package com.example.test;

import org.testng.Assert;
import org.testng.annotations.Test;
import com.example.message.MessageGenerator;

public class TestMessage2 {

    @Test
    public void test_welcome_message_2() {
        MessageGenerator obj = new MessageGenerator();
        Assert.assertEquals(obj.getWelcomeMessage(), "welcome");
    }

}

3.3 Use ivy to get the project dependencies, and declares the project scope.

ivy.xml


    

    
        
        
        
    

    
        
    

3.4 Run unit test

build.xml


    
        Running TestNG Test
    

    
    
    
    
    
    
    
    

    
    
        
        

        
        
        

    

    
    
        
        
            
        
    

    
    

      

        

        

                
      

    

    
    
        
        
        
    

    
    
        
        
    

    

$\{resources.dir}/testng.xml




    
        
            
            
        
    

それを実行します

$ ant testng

出力

testng:
   [testng] [TestNG] Running:
   [testng]   /Users/example/Documents/workspace/AntSpringMVC/resources/testng.xml
   [testng]
   [testng]
   [testng] ===============================================
   [testng] TestAll
   [testng] Total tests run: 2, Failures: 0, Skips: 0
   [testng] ===============================================
   [testng]

BUILD SUCCESSFUL
Total time: 3 seconds

完了しました。

ソースコードをダウンロード

ダウンロード–AntSpringMVC-TestNG-Example(90 KB)