Programing

프로그래밍의 비품은 무엇입니까?

lottogame 2020. 6. 13. 10:10
반응형

프로그래밍의 비품은 무엇입니까?


프로그래밍에 관해 이야기 할 때이 용어를 여러 번 들었지만 그 의미가 무엇인지 설명을 찾을 수 없었습니다. 좋은 기사 나 설명이 있습니까? 언급 할 가치가있는 것이 없습니다.


테스트 픽스처를 언급하고 있다고 생각합니다 .

테스트 픽스처의 목적은 결과가 반복 가능하도록 테스트가 실행되는 잘 알려져 있고 고정 된 환경이 있는지 확인하는 것입니다. 어떤 사람들은 이것을 테스트 컨텍스트라고 부릅니다.

비품의 예 :

- Loading a database with a specific, known set of data
- Erasing a hard disk and installing a known clean operating system installation
- Copying a specific known set of files
- Preparation of input data and set-up/creation of fake or mock objects

(출처 : Wikipedia, 위 링크 참조)

다음은 'Google Test'프레임 워크 문서의 실제 예제입니다 .


PHP 단위 테스트는 이것에 대해 잘 설명하고 있다고 생각합니다.

테스트 작성에서 가장 시간이 많이 걸리는 부분 중 하나는 코드를 작성하여 알려진 상태로 세상을 설정 한 다음 테스트가 완료되면 원래 상태로 되 돌리는 것입니다. 이 알려진 상태를 테스트의 치구라고합니다.

또한 Yii 문서는 픽스처 테스트가 좋은 형태로 설명되어 있습니다

자동화 된 테스트는 여러 번 실행해야합니다. 테스트 프로세스를 반복 가능하게하기 위해 고정 장치라고하는 알려진 상태에서 테스트를 실행하려고합니다. 예를 들어 블로그 애플리케이션에서 사후 작성 기능을 테스트하려면 테스트를 실행할 때마다 게시물에 대한 관련 데이터를 저장하는 테이블 (예 : Post 테이블, Comment 테이블)을 고정 된 상태로 복원해야합니다.

다음은 조명기 테스트의 간단한 예입니다

<?php
use PHPUnit\Framework\TestCase;

class StackTest extends TestCase
{
    protected $stack;

    protected function setUp()
    {
        $this->stack = [];
    }

    protected function tearDown()
    {
        $this->stack = [];
    }

    public function testEmpty()
    {
        $this->assertTrue(empty($this->stack));
    }

    public function testPush()
    {
        array_push($this->stack, 'foo');
        $this->assertEquals('foo', $this->stack[count($this->stack)-1]);
        $this->assertFalse(empty($this->stack));
    }

    public function testPop()
    {
        array_push($this->stack, 'foo');
        $this->assertEquals('foo', array_pop($this->stack));
        $this->assertTrue(empty($this->stack));
    }
}
?>

This PHP unit test has functions with names setUp and tearDown that before running your test you setup your data and on finished you can restore them to the initial state.


Exactly to that topic, JUnit has a well explained doc. Here is the link!

The related portion of the article is:

Tests need to run against the background of a known set of objects. This set of objects is called a test fixture. When you are writing tests you will often find that you spend more time writing the code to set up the fixture than you do in actually testing values.

To some extent, you can make writing the fixture code easier by paying careful attention to the constructors you write. However, a much bigger savings comes from sharing fixture code. Often, you will be able to use the same fixture for several different tests. Each case will send slightly different messages or parameters to the fixture and will check for different results.

When you have a common fixture, here is what you do:

Add a field for each part of the fixture Annotate a method with @org.junit.Before and initialize the variables in that method Annotate a method with @org.junit.After to release any permanent resources you allocated in setUp For example, to write several test cases that want to work with different combinations of 12 Swiss Francs, 14 Swiss Francs, and 28 US Dollars, first create a fixture:

public class MoneyTest {
    private Money f12CHF;
    private Money f14CHF;
    private Money f28USD;

    @Before public void setUp() {
    f12CHF= new Money(12, "CHF");
    f14CHF= new Money(14, "CHF");
    f28USD= new Money(28, "USD");
    }
}

In Xamarin.UITest it is explained as following:

Typically, each Xamarin.UITest is written as a method that is referred to as a test. The class which contains the test is known as a test fixture. The test fixture contains either a single test or a logical grouping of tests and is responsible for any setup to make the test run and any cleanup that needs to be performed when the test finishes. Each test should follow the Arrange-Act-Assert pattern:

  • Arrange – The test will setup conditions and initialize things so that the test can be actioned.
  • Act – The test will interact with the application, enter text, pushing buttons, and so on.
  • Assert – The test examines the results of the actions performed in the Act step to determine correctness. For example, the application may verify that a particular error message is displayed.

Link for original article of the above Excerpt

And within Xamarin.UITest code it looks like following:

using System;
using System.IO;
using System.Linq;
using NUnit.Framework;
using Xamarin.UITest;
using Xamarin.UITest.Queries;

namespace xamarin_stembureau_poc_tests
{
    [TestFixture(Platform.Android)]
    [TestFixture(Platform.iOS)]
    public class TestLaunchScreen
    {
        IApp app;
        Platform platform;

        public Tests(Platform platform)
        {
            this.platform = platform;
        }

        [SetUp]
        public void BeforeEachTest()
        {
            app = AppInitializer.StartApp(platform);
        }

        [Test]
        public void AppLaunches()
        {
            app.Screenshot("First screen.");
        }

        [Test]
        public void LaunchScreenAnimationWorks()
        {
            app.Screenshot("Launch screen animation works.");
        }
    }
}

Hope this might be helpful to someone who is in search of better understanding about Fixtures in Programming.


The term fixture varies based on context, programing language or framework.

1. A known state against which a test is running

One of the most time-consuming parts of writing tests is writing the code to set the world up in a known state and then return it to its original state when the test is complete. This known state is called the fixture of the test. PHP-Unit documentation

A test fixture (also known as a test context) is the set of preconditions or state needed to run a test. The developer should set up a known good state before the tests, and return to the original state after the tests. Wikipedia (xUnit)

2. A file containing sample data

Fixtures is a fancy word for sample data. Fixtures allow you to populate your testing database with predefined data before your tests run. Fixtures are database independent and written in YAML. There is one file per model. RubyOnRails.org

3. A process that sets up a required state. 

A software test fixture sets up the system for the testing process by providing it with all the necessary code to initialize it, thereby satisfying whatever preconditions there may be. An example could be loading up a database with known parameters from a customer site before running your test. Wikipedia

참고URL : https://stackoverflow.com/questions/12071344/what-are-fixtures-in-programming

반응형