Testing/it: Difference between revisions

From FreeCAD Documentation
No edit summary
(Created page with "Aggiungi funzione di test")
Line 125: Line 125:
=== Menu.MenuCreateCases ===
=== Menu.MenuCreateCases ===


Aggiungi funzione di test
Add test function


==Scripting==
==Scripting==

Revision as of 16:12, 10 September 2022

Test workbench icon

Introduzione

Test Framework non è in realtà un ambiente di modellazione, ma contiene un set di script Python per eseguire diversi test sui componenti principali di FreeCAD, al fine di eseguire il debug dei problemi. Vedere anche come individuare gli errori.

Puoi avviare i test dalla riga di comando, usando le opzioni -t o --run-test.

Avvia tutti i test:

freecad --run-test 0

Avvia solo alcuni test specificati, per esempio

freecad -t TestDraft

Se un test non ha bisogno della GUI, può anche essere eseguito in modalità console impostando l'opzione -c o --console in aggiunta. Questo di solito si traduce in tempi di avvio molto più rapidi poiché la GUI non viene caricata. Per esempio:

freecad -c -t TestPartDesignApp

Test menu

Ogni directory di primo livello in FreeCAD dovrebbe avere un file con i test che possono essere eseguiti per quel particolare ambiente di lavoro o modulo. Il file di solito inizia con la parola Test.

Per eseguire un test da FreeCAD, passare all'Ambiente Test, quindi Test commands → TestToolsGui → Self test → Select test name, quindi immettere il nome del file Python con i test; ad esempio, per l' Ambiente Draft, sarebbe TestDraft, quindi premere Start.

Funzioni di test

Questa è la lista delle applicazioni di test di 0.15 Git 4207:

TestAPP.All

Aggiungi funzione di test

BaseTests

Aggiungi funzione di test

UnitTests

Aggiungi funzione di test

Document

Aggiungi funzione di test

UnicodeTests

Aggiungi funzione di test

MeshTestsApp

Aggiungi funzione di test

TestDraft

Aggiungi funzione di test

TestSketcherApp

Aggiungi funzione di test

TestPartApp

Aggiungi funzione di test

TestPartDesignApp

Aggiungi funzione di test

TestPathApp

Ambiente Path casistiche di test:

  • depthTestCases:
  • PathTestUtils:
  • TestDressupDogbone: Test functionality of Dogbone dressup.
  • TestHoldingTags: Test functionality of Holding Tags dressup.
  • TestPathAdaptive: Test selection capability of Adaptive operation.
  • TestPathCore: Test core functionality of Path workbench.
  • TestPathDeburr: Test general functionality of Deburr operation.
  • TestPathGeom: Test various functions available in the PathGeom module.
  • TestPathHelix: Test general functionality of Helix operation.
  • TestPathLog: Test various functions available in the PathLog debugging and feedback module.
  • TestPathOpTools:
  • TestPathPreferences: Test various functions available in the PathPreferences module.
  • TestPathPropertyBag:
  • TestPathSetupSheet:
  • TestPathStock:
  • TestPathThreadMilling:
  • TestPathTool:
  • TestPathToolBit:
  • TestPathToolController:
  • TestPathTooltable:
  • TestPathUtil: Test various functions available in the PathUtil module.
  • TestPathVcarve: Test general functionality of Vcarve operation.
  • TestPathVoronoi:

Workbench

Aggiungi funzione di test

Menu

Aggiungi funzione di test

Menu.MenuDeleteCases

Aggiungi funzione di test

Menu.MenuCreateCases

Aggiungi funzione di test

Scripting

See also: FreeCAD Scripting Basics.

Get a list of all top-level test modules

FreeCAD.__unit_test__

Note that the test modules returned here depend on whether a GUI available or not. I.e. when executed in console mode, various tests ending in "Gui" are missing.

Run specific tests

There are various ways of running tests using Python's unittest library. FreeCAD's test framework removes some of the boiler plate for the most common cases.

Run all tests defined in a Python module:

import Test, TestFemApp
Test.runTestsFromModule(TestFemApp)

Run all tests defined in a Python class:

import Test, femtest.app.test_solver_calculix
Test.runTestsFromClass(femtest.app.test_solver_calculix.TestSolverCalculix)

Example 1

Within the Python Console of FreeCAD, the following code format may be used to run built-in tests. Replace the red "TestFem" text in the code below with the desired module test name.

  • For example, use "TestPathApp" to run all unit tests for the Path workbench unit test framework.
  • Submodules are available using dot notation, like "TestPathApp.TestPathAdaptive" to only run the Adaptive unit tests within the greater Path workbench test framework.
  • Multiple test modules or submodules may be combined by adding another `suite.addTest(...)` method call just like the one in the code below, but with a different module or submodule reference.
  • Output for the code below will be in the Report View panel within the FreeCAD GUI.
  • Code source is copied from post by FreeCAD forum user, sgrogan, in the unit tests per python topic, with credit there given to forum user, wmayer.
import unittest
suite = unittest.TestSuite()
suite.addTest(unittest.defaultTestLoader.loadTestsFromName("TestFem"))
r = unittest.TextTestRunner()
r.run(suite)

Additional Resources

Forum Topics