Adithya Shetty
Adithya Shetty

Reputation: 1287

How to not call a function inside another function in Unit test Dart?

I want to not call a few function calls that are inside a function that I am testing. I am new to testing. Since I am using SetUpALL((){}); to create a test suitable case instead of using the function.

main file:

class A{

 Future<void> function_1 () async {
   await another_function_1 // want to igonre this function in test.
 }

}

test file:

void main {
 setUpAll((){
 // statements.
 });
 group('tests',(
   test('test 1',(){

     A().function1(); // calling the function here for testing.

   });
 ){
});

}

Upvotes: 0

Views: 166

Answers (1)

Randal Schwartz
Randal Schwartz

Reputation: 44056

Welcome to the world of "Designing Testable Classes". You'll probably need to refactor this method to extract a testable part of the operations. Also, learn about Mockito to stub out dependent classes with your own behavior.

Upvotes: 2

Related Questions