parameterized

Pass lambda to parameterized NUnit test

浪子不回头ぞ 提交于 2019-12-03 12:28:05
I have a class with a bunch of overloaded operators: public static double[,] operator +(Matrix matrix, double[,] array) public static double[,] operator -(Matrix matrix, double[,] array) public static double[,] operator *(Matrix matrix, double[,] array) For all of them I'd like to test operands for null. I have an NUnit test for that: public void MatrixOperatorOperandIsNullThrows(Func<Matrix, double[,], double[,]> op) { Matrix m = null; var right = new double[,] {{1, 1}, {1, 1}}; Assert.Throws<ArgumentException>(() => op(m, right)); } How can I pass a lambda for each operator like (l,r) => l +

How do I test exceptions in a parameterized test?

◇◆丶佛笑我妖孽 提交于 2019-12-03 11:39:32
问题 In JUnit4 you can write parameterized unit tests by providing parameters collection in one method, which will be passed to the constructor of the test and testing in another method. If I have a parameter for which I expect an exception to be thrown, how do I specify that? 回答1: if (parameter == EXCEPTION_EXPECTED) { try { method(parameter); fail("didn't throw an exception!"); } catch (ExpectedException ee) { // Test succeded! } } 回答2: this is how i use junit parameterized test with expected

AndroidJUnit4 and Parameterized tests

只愿长相守 提交于 2019-12-03 11:24:58
问题 Google provide new classes to write tests for Android, and especially using jUnit 4: https://developer.android.com/tools/testing-support-library/index.html I was wondering if it is possible to use the AndroidJUnit4 runner, as well as the Parameterized one, from jUnit? 回答1: The current accepted answer doesn't provide an explanation, and the linked example isn't great at showing what needs to be done. Here's a more complete explanation that will hopefully save someone from spending the time I

Create multiple parameter sets in one parameterized class (junit)

痴心易碎 提交于 2019-12-03 02:59:01
问题 Currently I have to create a parameterized test class for every method that I want to test with several different inputs. Is there a way to add this together in one file? Right now there's CalculatorTestAdd.java which has a set of parameters that are used to check if the Add() function works properly. Is there a possbility for me to 'connect' this set to the Add() function and create an additional set meant for the Subtract() method and add this method in the same test class, resulting in one

Create multiple parameter sets in one parameterized class (junit)

夙愿已清 提交于 2019-12-02 17:36:50
Currently I have to create a parameterized test class for every method that I want to test with several different inputs. Is there a way to add this together in one file? Right now there's CalculatorTestAdd.java which has a set of parameters that are used to check if the Add() function works properly. Is there a possbility for me to 'connect' this set to the Add() function and create an additional set meant for the Subtract() method and add this method in the same test class, resulting in one file called CalculatorTest.java ? Yes. There's nothing special you have to do. For every set of value

performance of parameterized queries for different db's

天大地大妈咪最大 提交于 2019-12-02 17:12:43
问题 A lot of people know that it is important to use parameterized queries to prevent sql injection attacks. Parameterized queries are also much faster in sqlite and oracle when doing online transaction processing because the query optimizer doesn't have to reparse every parameterized sql statement before executing. I've seen sqlite becoming 3 times faster when you use parameterized queries, oracle can become 10 times faster when you use parameterized queries in some extreme cases with a lot of

Is C++ OTL SQL database library using parameterized queries under the hood, or string concat?

流过昼夜 提交于 2019-12-01 07:35:49
I've been looking at the OTL (Oracle, Odbc and DB2-CLI Template Library) for C++ database access. I'm unsure of whether the query I pass in is converted to a parameterized query for the underlying database, or if it's basically just concatenating all the arguments into one big string and passing the query to the database that way. I see that the query you pass in to it can include type information for the arguments, but what happens between then and the query hitting the database, I can't tell. Brett Rossier OTL author's response to my e-mail: OTL passes queries with placeholders into the DB

Is C++ OTL SQL database library using parameterized queries under the hood, or string concat?

末鹿安然 提交于 2019-12-01 05:33:59
问题 I've been looking at the OTL (Oracle, Odbc and DB2-CLI Template Library) for C++ database access. I'm unsure of whether the query I pass in is converted to a parameterized query for the underlying database, or if it's basically just concatenating all the arguments into one big string and passing the query to the database that way. I see that the query you pass in to it can include type information for the arguments, but what happens between then and the query hitting the database, I can't

Junit Parameterized tests together with Powermock - how?

*爱你&永不变心* 提交于 2019-11-30 06:04:08
I've been trying to figure out how to run parameterized tests in Junit4 together with PowerMock. The problem is that to use PowerMock you need to decorate your test class with @RunWith(PowerMockRunner.class) and to use parameterized tests you have to decorate with @RunWith(Parameterized.class) From what I can see they seem mutually excluded!? Is this true? Is there any way around this? I've tried to create a parameterized class within a class running with PowerMock; something like this: @RunWith(PowerMockRunner.class) class MyTestClass { @RunWith(Parameterized.class) class ParamTestClass { //

A way to see query after parameters are applied?

大憨熊 提交于 2019-11-29 17:15:01
问题 In a C# application, I'm building a query by creating a query string with parameters, then to the command adding the parameters and their values. For example: string query = "UPDATE USERS u SET u.username = @PARM_USERNAME " + "WHERE u.id = @PARM_USERID "; command.Parameters.AddWithValue("@PARM_USERNAME", user.username); command.Parameters.AddWithValue("@PARM_USERID", user.id); command.Connection.Open(); int res = command.ExecuteNonQuery(); It would be beneficial to see the query with