필터 지우기
필터 지우기

I want to test a function in a class but it relies on the object which isn't called

조회 수: 2 (최근 30일)
So I have a class which calls another class then the method in the lower class. I have now moved onto unit testing this functions. In the lower class the method has a series of if statements which depends on the object. However the object isn't used when calling the function.
It would be very complicated to instantiate the upper class prior to instantiating the lower class then calling the method. So that the object is in use. Can I just call the method using the object as an input?
  댓글 수: 3
Katherine
Katherine 2024년 2월 1일
Sorry I am not used to class and I did not make the class so I am sorry if I didn't explain it well
Bascially the tests are failing, when something somewhere else changes. I believe this value is changed within the object at a higher level and passed down. So when I test the method in the lower class, the object isn't chnaged as its done in isolation, so the if statement is never triggered, so the result is returned wrong and the test fails.
When calling the method after instantiating the class in the test its " Output = className(Input)" but it never calls the now changed object.
When running the entire script I can save the changed object. But since its never called as shown above, how can I use it?
This call does not have static methods but in another class there is.
Does this make more sense?
Steven Lord
Steven Lord 2024년 2월 1일
I think you should probably show a small concrete example of what you're describing. I'm not certain I understand what your implementation is doing from this prose description. In this case, a small chunk of code may be worth at least a few hundred words.

댓글을 달려면 로그인하십시오.

답변 (0개)

카테고리

Help CenterFile Exchange에서 Construct and Work with Object Arrays에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by