Koj yuav thuam cov chav kawm zoo li cas?
Koj yuav thuam cov chav kawm zoo li cas?

Video: Koj yuav thuam cov chav kawm zoo li cas?

Video: Koj yuav thuam cov chav kawm zoo li cas?
Video: Vim Li cas Koj Yuav tsum Tau Kawm English, Thiab Yuav Kawm Li cas Thiaj Yooj Yim 2024, Kaum ib hlis
Anonim

Tsim ib qho interface rau DriverManager, thuam qhov no interface, txhaj nws ntawm qee yam kev vam khom txhaj tshuaj thiab txheeb xyuas qhov ntawd thuam . Kev soj ntsuam: Thaum koj hu txoj kev zoo li qub hauv ib zoo li qub qhov chaw, koj yuav tsum tau hloov lub chav kawm hauv @PrepareForTest. ces, koj yuav tau npaj lub chav kawm txoj cai no nyob hauv.

Ntawm no, peb puas tuaj yeem thuam cov txheej txheem zoo li qub?

Mockito tso cai rau peb tsim thuam khoom. Txij li thaum txoj kev zoo li qub belongs rau chav kawm, tsis muaj txoj hauv kev hauv Mockito rau mock cov txheej txheem static . Txawm li cas los xij, peb ua tau siv PowerMock nrog rau Mockito moj khaum rau mock cov txheej txheem static.

Peb puas tuaj yeem thuam txoj hauv kev zoo li C#? 4 Teb. Moq (thiab lwm yam DynamicProxy-based thuam frameworks) ua tsis tau thuam txhua yam uas tsis yog virtual lossis abstract txoj kev . Xwb, koj ua tau refactor koj tsim rau abstract hu rau txoj kev zoo li qub , thiab muab qhov kev xav no rau koj chav kawm los ntawm kev txhaj tshuaj tiv thaiv.

Ib yam li ntawd, tib neeg nug, peb puas tuaj yeem thuam txoj hauv kev siv MOQ?

Mocking Static Methods Cov cuab yeej pub dawb zoo li Moq tau nkaus xwb thuam interfaces lossis virtual / abstract txoj kev ntawm cov chav kawm nrog rau pej xeem default constructor. Yog koj xav tau tiag tiag mock cov txheej txheem static , koj yuav tsum tau siv cov cuab yeej ua lag luam xws li Microsoft Fakes (ib feem ntawm Visual Studio Enterprise) lossis Typemock Isolator.

Vim li cas cov txheej txheem zoo li qub tsis zoo?

Hauv ntiaj teb OO txoj kev zoo li qub yog anti-teeb meem. Lawv tsis tas yuav yog phem , tab sis lawv yog cov txaus ntshai, vim lawv siv tsis raug. Tsuas muaj ob qhov xwm txheej thaum txoj kev zoo li qub los yog hloov pauv tau raug siv thiab nws tsis yog kev qias neeg. Cov txheej txheem zoo li qub yog ib qho tseem ceeb thiab siv tau txoj kev ntawm object creation.

Pom zoo: