উদাহরণ সহ টেস্ট ইগনোর এবং নির্দিষ্ট টেস্ট চালানো

TestNG এর মধ্যে টেস্ট ইগনোর করা এবং নির্দিষ্ট টেস্ট চালানো - টেস্টএনজি (TestNG) - Java Technologies

330

TestNG ফ্রেমওয়ার্ক ব্যবহার করে নির্দিষ্ট টেস্ট চালানো বা কিছু টেস্ট ইগনোর করা যায়। এটি টেস্টিং প্রক্রিয়াকে আরও নমনীয় এবং কার্যকর করে। এখানে টেস্ট ইগনোর করা এবং নির্দিষ্ট টেস্ট চালানোর বিভিন্ন উপায় উদাহরণসহ ব্যাখ্যা করা হলো।


টেস্ট ইগনোর করা (Test Ignore)

enabled প্যারামিটার ব্যবহার করে

TestNG-তে @Test এনোটেশনের enabled প্যারামিটার ব্যবহার করে সহজেই কোনো টেস্ট মেথড ইগনোর করা যায়।

উদাহরণ:

import org.testng.annotations.Test;

public class IgnoreTestExample {

    @Test
    public void testMethod1() {
        System.out.println("This test will run.");
    }

    @Test(enabled = false)
    public void testMethod2() {
        System.out.println("This test will be ignored.");
    }
}

আউটপুট:

  • testMethod1 চালানো হবে।
  • testMethod2 ইগনোর করা হবে।

নির্দিষ্ট টেস্ট চালানো (Running Specific Tests)

১. টেস্ট গ্রুপ ব্যবহার করে নির্দিষ্ট টেস্ট চালানো

TestNG-তে গ্রুপিং ফিচার ব্যবহার করে নির্দিষ্ট টেস্ট রান করা যায়। মেথডগুলোতে @Test(groups = "groupName") ব্যবহার করে গ্রুপিং করতে হয়।

উদাহরণ:

import org.testng.annotations.Test;

public class GroupTestExample {

    @Test(groups = {"smoke"})
    public void testMethod1() {
        System.out.println("Smoke test 1 is running.");
    }

    @Test(groups = {"regression"})
    public void testMethod2() {
        System.out.println("Regression test 1 is running.");
    }

    @Test(groups = {"smoke", "regression"})
    public void testMethod3() {
        System.out.println("Smoke and Regression test is running.");
    }
}

testng.xml কনফিগারেশন:

<!DOCTYPE suite SYSTEM "https://testng.org/testng-1.0.dtd">
<suite name="TestSuite">
    <test name="GroupedTests">
        <groups>
            <run>
                <include name="smoke"/>
            </run>
        </groups>
        <classes>
            <class name="com.example.tests.GroupTestExample"/>
        </classes>
    </test>
</suite>

আউটপুট:

শুধু smoke গ্রুপের টেস্ট (testMethod1 এবং testMethod3) রান হবে।


২. নির্দিষ্ট মেথড রান করা

testng.xml ফাইল ব্যবহার করে নির্দিষ্ট মেথড রান করা যায়।

উদাহরণ:

import org.testng.annotations.Test;

public class SpecificMethodTestExample {

    @Test
    public void testMethod1() {
        System.out.println("Test Method 1 is running.");
    }

    @Test
    public void testMethod2() {
        System.out.println("Test Method 2 is running.");
    }

    @Test
    public void testMethod3() {
        System.out.println("Test Method 3 is running.");
    }
}

testng.xml কনফিগারেশন:

<!DOCTYPE suite SYSTEM "https://testng.org/testng-1.0.dtd">
<suite name="TestSuite">
    <test name="SpecificMethodTest">
        <classes>
            <class name="com.example.tests.SpecificMethodTestExample">
                <methods>
                    <include name="testMethod2"/>
                </methods>
            </class>
        </classes>
    </test>
</suite>

আউটপুট:

শুধু testMethod2 রান হবে।


টেস্ট স্কিপ করা (Test Skip)

TestNG-তে শর্ত সাপেক্ষে টেস্ট স্কিপ করা যায়। throw new SkipException() ব্যবহার করে এটি করা হয়।

উদাহরণ:

import org.testng.SkipException;
import org.testng.annotations.Test;

public class SkipTestExample {

    @Test
    public void testMethod1() {
        System.out.println("This test will run.");
    }

    @Test
    public void testMethod2() {
        System.out.println("This test will be skipped.");
        throw new SkipException("Skipping testMethod2 for demonstration.");
    }
}

আউটপুট:

  • testMethod1 রান হবে।
  • testMethod2 স্কিপ করা হবে।

সারাংশ

  • ইগনোর: @Test(enabled = false) ব্যবহার করে কোনো টেস্ট ইগনোর করা যায়।
  • নির্দিষ্ট টেস্ট চালানো:
    • গ্রুপ নির্ধারণ করে (উদাহরণ: @Test(groups = "smoke"))।
    • testng.xml ফাইলের <methods> ট্যাগ ব্যবহার করে।
  • স্কিপ: SkipException ব্যবহার করে শর্ত সাপেক্ষে টেস্ট স্কিপ করা যায়।

TestNG-এর এই ফিচারগুলো টেস্ট কেস ম্যানেজমেন্টকে আরও কার্যকর করে এবং জটিল প্রোজেক্টে টেস্ট কনফিগারেশন সহজ করে।

Content added By
Promotion

Are you sure to start over?

Loading...