YAxUnit

repository·develop·Indexed 43 days ago

https://github.com/bia-technologies/yaxunit

A testing extension designed to facilitate the execution and reporting of tests, primarily for the 1C:Enterprise ecosystem.

Tokens
105.9K
Snippets
259
Records
378
Agent score
55%

What's inside YAxUnit

  1. Overview of YAxUnit auxiliary modules

    develop

    YAxUnit provides several auxiliary modules designed to simplify test development by extending the core engine's capabilities. These modules cover data retrieval, collection manipulation, string processing, logging, object creation, and error handling.

    Available auxiliary modules include:

    • ЮТЗапрос (queries.md): Methods for retrieving data from the information database.
    • ЮТКоллекции (collections.md): Universal methods for working with various collections such as arrays, tables, and structures.
    • ЮТСтроки (/api/ЮТСтроки): Universal methods for string manipulation.
    • ЮТЛогирование (/api/ЮТЛогирование): Logging methods.
    • ЮТФабрика (/api/ЮТФабрика): Methods for creating various engine objects required during test development.
    • ЮТКомпоненты (/api/ЮТКомпоненты): Provides access to external engine components.
    • ЮТМетаданные (/api/ЮТМетаданные): Methods for working with metadata.
    • ЮТРегистрацияОшибок (/api/ЮТРегистрацияОшибок): Methods for error registration and handling.
    • ЮТИсключения (/api/ЮТИсключения): Methods for formatting exception messages.
  2. Overview of YAxUnit capabilities

    develop

    YAxUnit is an open-source testing framework designed for the 1C:Enterprise platform. It provides a comprehensive suite of tools for automated testing, including:

    • Test Management: Creation of test cases, test suites, and execution contexts.
    • Assertions & Predicates: Built-in assertion modules and predicates for validating test results.
    • Mocking: Mockito-like mocking and interception capabilities to isolate components.
    • Reporting: Generation of high-quality reports, including jUnit (for CI/CD integration) and Allure (for advanced analytics).
    • Smoke Testing: Specialized smoke tests provided via the exts/smoke extension.
    • CI/CD Integration: Designed to work with modern pipelines like GitHub Actions and Jenkins.
  3. Overview of YAxUnit testing capabilities

    develop

    YAxUnit is a powerful testing tool designed for solutions built on the 1C:Enterprise platform. It is built following testing best practices and provides a comprehensive suite of features to streamline the development and verification of 1C code.

    Key capabilities include:

    • Test Engine: Executes tests and generates detailed reports in various formats.
    • Assertions: Provides tools to verify expected results against actual outcomes, ensuring precision in testing.
    • Test Data Management: Powerful tools for creating, deleting, and searching for required test data.
    • Fluent API: Supports fluent expressions to make test code more readable, understandable, and maintainable.
    • Extensibility: Allows developers to extend functionality to meet unique project requirements.
    • EDT Plugin: A dedicated plugin for 1C:Enterprise Development Tools (EDT) that enables running and debugging tests with a single click.
  4. Overview of YAxUnit

    develop

    YAxUnit is an extension designed for running tests (Расширение для запуска тестов). It provides a testing interface and reporting capabilities, as shown in its UI reports.

    For detailed usage instructions, configuration, and API details, refer to the official documentation site.

  5. Use the ЮТКонструкторТекста module for text manipulation

    develop

    The ЮТКонструкторТекста module is designed for creating, modifying, and managing collections of text strings. It supports template-based formatting, string insertion, indentation (tabulation), and line breaks.

    Key features include:

    • Chaining: Most methods return the current object, allowing you to chain multiple operations in a single statement.
    • Template Formatting: Easily inject parameters into strings using placeholders.
    • Delimiter Management: Control how lines are joined when retrieving the final text.

    Note: You must call Инициализировать() before using the module's methods.

    Объект = Новый ObjectModule;
    Объект.Инициализировать();
  6. Advantages of using Mockito in YAxUnit

    develop

    Mockito provides several key benefits for testing complex systems within YAxUnit:

    • Flexibility: You can mock both exported and private methods and configure specific call conditions. This allows for high isolation of individual system components.
    • Ease of Use: The API is designed to be intuitive, using fluent expressions that make mock configuration readable and fast.
    • Global Context: All configurations and statistics are stored in a single central location. This simplifies management and allows you to easily track method calls and verify their correctness.
  7. Use UI helpers for test data management

    develop

    YAxUnit provides several UI helpers to streamline the creation and management of test data. These tools allow you to automate code generation for test data, build complex objects, and visually edit data layouts.

    Available helpers include:

    • Test Data Code Generator: Automates the creation of code required for test data.
    • Object Builder Generator: Generates code for building specific objects.
    • Test Data Layout Editor: A visual tool for editing the structure and layout of your test data.
  8. Overview of the Object Builder for test data generation

    develop
    The Конструктор объекта (Object Builder) is a powerful and flexible tool designed for creating test data within 1C. It features a fluent interface that allows developers to easily configure objects, tabular sections (табличные части), and attributes (реквизиты). It also supports the automatic generation of dummy/fictitious values, which simplifies the test writing process and improves test data quality.
  9. What is Mockito and how to use it for mocking

    develop

    Mockito is a module inspired by the Java Mockito framework. It allows you to change system behavior by replacing method results, disabling algorithms, or bypassing checks. This is useful for testing code that depends on external systems, verifying method parameters, or isolating specific logic.

    Capabilities:

    • Change method behavior: Specify return values, throw exceptions, or prevent execution.
    • Configure conditions: Set conditions for method parameters so changes apply only in specific cases.
    • Mock private and exported methods: Mock public and private methods of objects, documents, catalogs, etc.
    • Collect statistics: Observe method calls to ensure they are executed with correct parameters.

    Limitations:

    • Cannot execute arbitrary logic during a method call.
    • Cannot change method parameters.
    • Cannot store call results during statistics collection.
    • Scope: Mockito works via configuration method borrowing (&Вместо). It can only mock methods defined within the configuration itself. It cannot mock:
      • Platform methods (built-in 1C methods).
      • Extension methods.
      • Methods of external processing or reports.
    ТелоОтвета = Новый Структура("success": Истина);
    // Настройка мокирования
    Мокито.Обучение(РаботаСHTTP)
      .Когда("ОтправитьЗапрос").Вернуть(
        ЮТест.Данные().HTTPОтвет()
          .УстановитьКодСостояния(200)
          .УстановитьТело(ТелоОтвета))
      .Прогон();
    
    // Тестовый прогон
    Результат = РаботаСHTTP.ОтправитьЗапрос("https://example.com");
    
    // Проверка
    ЮТест.ОжидаетЧто(Результат.КодСостояния).Равно(200);
  10. Organize test data helper modules by project scale

    develop

    To maintain a scalable test suite, follow these organizational patterns for your data constructor modules:

    1. Small Solutions: Use a single common module for all constructor methods.
    2. Small to Medium Configurations: Create modules organized by subsystems (e.g., accounting slices or functional areas).
    3. Large/Complex Projects: Create a dedicated module for each specific object or functional area to manage complexity.
  11. Use YAxUnit assertions to verify requirements

    develop

    In YAxUnit, assertions are used to describe and verify expectations (requirements) for the functionality being tested. Instead of manually checking conditions with If statements and throwing exceptions, you use the ЮТест.ОжидаетЧто() mechanism.

    Using assertions provides several benefits:

    1. Readable Tests: Method chains form human-readable sentences.
    2. Clear Error Messages: When an assertion fails, YAxUnit generates detailed, "friendly" error messages that explain exactly what was expected versus what was actually received.
    3. Error Differentiation: Assertion failures are marked as a specific type of error, allowing you to distinguish between a failed expectation (the test logic is correct, but the system behavior changed) and a code crash (an actual exception in the system under test).

    To improve maintainability, use indentation and formatting for long assertion chains, and avoid writing excessive assertions that aren't necessary for the specific test scenario.

    ЮТест.ОжидаетЧто(ДанныеЗаписи)
        .Свойство("Поставщик").Равно(ДанныеОбъекта.Поставщик)
        .Свойство("Товары")
            .ИмеетДлину(1)
            .Свойство("Товары[0].НомерСтроки").Равно(2)
            .Свойство("Товары[0].Товар").Равно(ДанныеОбъекта.Товары[0].Товар);