基于模型的嵌入式開發流程
Unit testing is not enough – so let's start using model-based testing to improve our workflows.
單元測試還不夠–因此,讓我們開始使用基于模型的測試來改善我們的工作流程。
Software testing is an important phase in building a scalable software system that usually has critical functions, business flows/logic, and connected external entities. This distributed nature of software systems induces a certain level of complexity when writing tests for each unit, function, or flow.
軟件測試是構建可伸縮軟件系統的重要階段,該系統通常具有關鍵功能,業務流程/邏輯以及連接的外部實體。 在為每個單元,功能或流程編寫測試時,軟件系統的這種分布式性質會引起一定程度的復雜性。
There are various types of testing approaches you can use. The best approach you can employ seamlessly is model-based testing. In simple terms, this means creating a model of your system (more like a digital twin that describes every aspect of the system) and generating a test against the model.
您可以使用多種測試方法。 您可以無縫采用的最佳方法是基于模型的測試。 簡單來說,這意味著創建系統模型(更像是描述系統各個方面的數字孿生模型)并針對該模型生成測試。
什么是基于模型的測試? (What Is Model-Based Testing?)
First, we need to know that a model is basically the description and representation of how we expect the system to work. The system’s processes can be defined based on the series of input sequences, actions, functions, output, and flow of data starting from input to the output received.
首先,我們需要知道模型基本上是我們期望系統工作方式的描述和表示。 可以基于一系列輸入序列,操作,功能,輸出以及從輸入到接收到的輸出的數據流來定義系統的過程。
We must be able to determine all these behaviors while testing, and a model helps us do just that seamlessly. With that, we can then generate tests automatically based on the system models.
我們必須能夠在測試時確定所有這些行為,并且模型可以幫助我們無縫地做到這一點。 這樣,我們便可以基于系統模型自動生成測試。
Basically, model-based testing is a software testing technique in which the test cases are generated from a model that describes the functional aspects of the system under test. This is a new software testing method that employs a secondary, lightweight, time-efficient implementation of a software build which is called a model.
基本上,基于模型的測試是一種軟件測試技術,其中從描述了被測系統功能方面的模型生成測試用例。 這是一種新的軟件測試方法,該方法采用稱為模型的軟件構建的次要,輕量級,省時的實現。
We take this model coupled with the system requirements and generate efficient test cases. This software testing method is applicable to both hardware and software testing.
我們將此模型與系統需求結合起來,并生成有效的測試用例。 此軟件測試方法適用于硬件和軟件測試。
為什么以及如何改善工作流程 (Why and How It Improves Workflow)
Automating tests is unavoidable as it enables faster and more efficient software testing. You can streamline your workflow and use the latest development methodologies to improve it.
自動化測試是不可避免的,因為它可以實現更快,更有效的軟件測試。 您可以簡化工作流程并使用最新的開發方法進行改進。
Most software developers and teams find it challenging to create and update test cases in an environment of constantly changing dependencies and requirements.
大多數軟件開發人員和團隊都發現,在依賴和要求不斷變化的環境中創建和更新測試用例具有挑戰性。
From employing the simplest functional tests to heavyweight methods like E2E and so many others, there have been numerous testing methods designed for improving testing reliability and effectiveness.
從使用最簡單的功能測試,以重量級的方法,如E2E和許多其他人 ,已經有不少測試方法專為提高測試的可靠性和有效性。
There’s absolutely nothing wrong with these methods. However, these test cases have to be written manually for each scenario. Whenever there’s a change in the system requirements, you have to update each test case affected by the change.
這些方法絕對沒有錯。 但是,必須針對每種情況手動編寫這些測試用例。 只要系統要求發生變化,就必須更新受更改影響的每個測試用例。
Below, you’ll find a graphical exemplification of the model-based testing process:
在下面,您將找到基于模型的測試過程的圖形示例:
These models are used to generate automated test cases using MBT tools as they describe the expected behaviour of the system being tested.
這些模型用于使用MBT工具生成自動化測試用例,因為它們描述了被測系統的預期行為。
We basically have two steps here:
我們基本上有兩個步驟:
- Creating models to describe the behavior and processes of the system. 創建模型來描述系統的行為和過程。
- Using MBT tools like Spec Explorer, Graphwalker, fMBT or Modbat, to interpret the models and generate test scripts for automated testing. 使用諸如Spec Explorer,Graphwalker,fMBT或Modbat之類的MBT工具來解釋模型并生成用于自動測試的測試腳本。
When working with model-based testing, the model creation phase should be part of the software development life cycle and integrated as part of product design from the phase of requirements specification.
在進行基于模型的測試時,模型創建階段應成為軟件開發生命周期的一部分,并應從需求規范階段集成為產品設計的一部分。
This allows the software development team to focus their attention on building a testable product and models that enhance user experience.Model-based testing can improve our workflow by:
這使軟件開發團隊可以將精力集中在構建可測試的產品和可增強用戶體驗的模型上。基于模型的測試可以通過以下方式改善我們的工作流程:
- Reducing the time spent on writing tests and allowing developers to focus on writing models to cover system requirements only and build a testable application from the onset. 減少花費在編寫測試上的時間,并允許開發人員專注于編寫僅滿足系統需求的模型,并從一開始就構建可測試的應用程序。
- Reducing test suite maintenance and generating more tests. 減少測試套件維護并生成更多測試。
- Helping the team create automated scripts and increasing test coverage when used with testing tools and automation frameworks. 與測試工具和自動化框架一起使用時,幫助團隊創建自動化腳本并增加測試覆蓋率。
如何實施基于模型的測試 (How to Implement Model-Based Testing)
Implementing model-based testing can’t be introduced suddenly to a system, as it has to be done gradually. It will be too much to introduce it to the entire system’s processes and operations.
基于模型的測試的實現不能突然引入系統,因為它必須逐步完成。 將其引入整個系統的流程和操作將是太多了。
It’s best fitted for the initial stage of the product, as things are still very minute. It's easy to integrate with the system requirements then, because as things get bigger you get to update just the model.
因為事情仍然很微小,所以它最適合產品的初始階段。 這樣就很容易與系統需求集成,因為隨著事情的發展,您只需要更新模型即可。
To implement model-based testing you have to start with creating the models. Models can can cover any level of requirements, from business logic to user story, and can be connected to each other.
要實施基于模型的測試,您必須先創建模型。 模型可以涵蓋從業務邏輯到用戶故事的任何級別的需求,并且可以彼此連接。
Then you can automatically generate test cases based on the models once they are done creating it. And of course, if you make any changes to the models, the tests will be updated automatically.
然后,一旦完成創建模型,您便可以基于模型自動生成測試用例。 當然,如果您對模型進行了任何更改,測試將自動更新。
You can easily integrate these tests into your CI processes and tools once you’re able to generate automated tests from models.
一旦能夠從模型生成自動化測試,就可以輕松地將這些測試集成到CI流程和工具中。
基于模型的測試的優勢
(Advantages of Model-Based Testing)
- Optimizes the software testing time and cost 優化軟件測試時間和成本
- You can generate test scripts for each scenario with just a push of a button. 您只需按一下按鈕,就可以為每種情況生成測試腳本。
- This ensures the software testing team can communicate expected system behavior. 這樣可以確保軟件測試團隊可以傳達預期的系統行為。
- Enables early detection of requirement irregularities. 能夠及早發現需求違規情況。
- Automated test case generation and execution make the overall testing solution more efficient and less error-prone. 自動化的測試用例生成和執行使整個測試解決方案更加有效,并且不易出錯。
- It helps generate a minimal number of test cases to validate a given functional or data flow to ensure that the system under test works flawlessly and never does anything undesirable. 它有助于生成最少數量的測試用例,以驗證給定的功能或數據流,以確保被測系統能夠完美地工作,并且絕不會做任何不希望的事情。
- Project maintenance is minute. 項目維護非常簡單。
基于模型的測試的缺點
(Disadvantages of Model-Based Testing)
- Demands a high amount of investment as well as effort. 需要大量的投資和精力。
- Requires skilled and disciplined software tester. 需要熟練且訓練有素的軟件測試人員。
- The first test case takes longer to generate as it requires more advance work than traditional manual testing. 與傳統的手動測試相比,第一個測試用例的生成時間更長,因為它需要更多的工作。
- The learning curve of model-based testing is pretty steep and its complexity makes it harder to understand for beginners. 基于模型的測試的學習曲線非常陡峭,其復雜性使初學者很難理解。
與UI測試有何不同 (How it's Different from UI Testing)
Basically we know what model-based testing is now, and we already figured out the benefits of using it over using the traditional testing method.
基本上,我們知道現在基于模型的測試是什么,并且我們已經弄清楚了使用它比使用傳統測試方法的好處。
UI (User Interface/Frontend Testing) is a type of software testing that simply involves the process of testing the function of the user interface, making sure the interface of the system is reacting as it’s supposed to.
UI(用戶界面/前端測試)是一種軟件測試 ,僅涉及測試用戶界面功能的過程,以確保系統界面能夠按預期進行響應。
This process involves manual testing, and each test scenario has to be written by hand. Any changes made to the UI will break the whole test case unless it's updated along with the changes. It employs the use of WebDrivers and most times Selenium in order to fully simulate the way users interact with the interface and validate the expected output.
此過程涉及手動測試,并且每個測試方案都必須手動編寫。 對UI所做的任何更改都會破壞整個測試用例,除非它與更改一起更新。 它充分利用了WebDrivers和大多數Selenium的用法,以完全模擬用戶與界面的交互方式并驗證預期的輸出。
UI testing can be employed in any stage of the product as it clearly doesn’t have much requirement and the learning curve is very easy compared to MBT.
UI測試可以用于產品的任何階段,因為它顯然不需要太多,并且與MBT相比,學習曲線非常容易。
The cost of testing is quite low and could be ground down to zero. The time spent can also be little. Maintenance can be very high depending on the complexity of the product interface.
測試成本非常低,可以降低到零。 花費的時間也可以很少。 維護可能非常高,具體取決于產品界面的復雜性。
It doesn’t require a very skillful developer or software. Any developer with basic testing knowledge can pick this up. There are so many differences when you look into this more, however, both are good for different use cases.
它不需要非常熟練的開發人員或軟件。 任何具有基本測試知識的開發人員都可以掌握。 當您對此進行更多研究時,有很多差異,但是,兩者都適用于不同的用例。
結論 (Conclusion)
Model-based testing is a powerful, cost-efficient, and profitable technique for large businesses in the long run.
從長遠來看,基于模型的測試對于大型企業而言是一種強大,經濟高效且有利可圖的技術。
However, introducing this approach to large company processes can be a big challenge, especially when it involves overhauling their entire approach to software development and testing.
但是,將這種方法引入大型公司的流程可能是一個巨大的挑戰,尤其是當涉及對軟件開發和測試的整個方法進行全面檢查時。
Model-based testing has to become a part of the development workflow, but this comes with its own challenges, including changes to the entire infrastructure. It also makes an already steep learning curve even more challenging.
基于模型的測試必須成為開發工作流程的一部分,但這帶來了自身的挑戰,包括更改整個基礎架構。 這也使本已陡峭的學習曲線更具挑戰性。
Luckily, there are some things that can help identify when model-based testing can really be useful. For example, if you have an infinite set of systems with requirements you can cover in different ways. Or if you have a distributed or reactive system, that can also be a reason to consider this approach.
幸運的是,有些事情可以幫助您確定何時基于模型的測試真正有用。 例如,如果您有無限多個具有要求的系統,則可以用不同的方式進行介紹。 或者,如果您有分布式或React性系統,那也可能是考慮使用此方法的原因。
Model-based testing can go a long way in testing and save significant time and effort when implemented properly.
基于模型的測試可以在測試中走很長一段路,如果正確實施,可以節省大量時間和精力。
翻譯自: https://www.freecodecamp.org/news/improve-your-workflow-using-model-based-testing/
基于模型的嵌入式開發流程