java - Can junit test method throw an exception? -


Can you please tell me the general practice to write example alias genus test, which throws an exception, example For example, the class A {public string F (int param) throws an exception (if (absolute == 100500) throw a new exception (); return "";}} private object object = new A (); @Test Public Zero Test Some Throws Exception {String Expected = ""; AssertEquals (object.f (5), Expected);}

In fact, Method f () does not throw an exception for that parameter (5), but I still have to declare that exception.

Yes it's perfectly ok, and if it throws an exception, then the test will be treated as unsuccessful.

The method requires that the method break a exception , even if you know that there is no specific case (this is done by the check compiler).

In this case, what do you expect object.f (5) gives an empty string Any other result (without empty string or throw an exception) will result in unsuccessful test case .


Comments

Popular posts from this blog

apache - 504 Gateway Time-out The server didn't respond in time. How to fix it? -

c# - .net WebSocket: CloseOutputAsync vs CloseAsync -

c++ - How to properly scale qgroupbox title with stylesheet for high resolution display? -