Это потому, что вы пытаетесь удалить некоторые элементы с List.remove(position)
последовательно. Вы, вероятно, удаляете ту же позицию элемента с помощью следующего кода:
asset_type.remove(position);
asset_count.remove(position);
asset_value.remove(position);
AssetDetailsActivity.assetValueId.remove(position);
AssetDetailsActivity.assetCountId.remove(position);
AssetDetailsActivity.assetTypeId.remove(position);
Источником проблемы обычно является то, что вы забыли, что не примитивный тип данных всегда передается ссылка, например: а List
.
В следующем типичном адаптере RecylerView список (List<YourDatum> data
) передается по ссылке:
public class YourAdapter extends
RecyclerView.Adapter<YourAdapter.ViewHolder> {
..
private List<YourDatum> mData;
public YourAdapter(List<YourDatum> data) {
mData = data;
}
}
и мы обычно передаем список через конструктор с помощью:
[112 ] Итак, и YourActivity.mData
, и YourAdapter.mData
указывают на одно и то же место. Следовательно, всякий раз, когда вы удаляете элемент из YourActivity.mData
, элемент YourAdapter.mData
также удаляется.
Теперь вам нужно использовать только следующий код для вашего дела:
asset_type.remove(position);
asset_count.remove(position);
asset_value.remove(position);
// the following is not needed because it's incorrect
// AssetDetailsActivity.assetValueId.remove(position);
// AssetDetailsActivity.assetCountId.remove(position);
// AssetDetailsActivity.assetTypeId.remove(position)
Я нашел способ, который подходит для моих целей
Создайте один тестовый пример и отметьте его атрибутом TestCaseSource, например
[Test, TestCaseSource("GetTestCases")]
public void TestFile(string filename)
{
//do test
}
Затем напишите GetTestCases для чтения всех имен файлов в каталоге
private static string[] GetTestCases()
{
return GetAllFilesInCurrentDirectory();
}
Затем, когда я запускаю NUnit, я получаю список тестов, которые нужно запустить (перечисленные в TestFile).
If you are not going to be adding files to that directory over time and have a set of filenames to pass in as an input to a generic test, try using the RowTest NUnit extension (part of the std distrib post v2.4.7) - You'd be able to see each test case - input combination individually in the GUI grouped under a single node.
If you are going to be adding files to that directory, I'd write a single NUnit TestCase that loops over a list of files obtained at runtime and calls the generic test method with each filepath. Use a collecting parameter to collect failing test file names - at the end you assert. You wouldn't be able to see each test case individually but you'd have readable simple test code.
Assert.AreEqual(listOfFailedFiles.Length, 0, PrettyPrint(listOfFailedFiles))
Я знаю, что это немного неясно, но я использовал сценарий в прошлое, чтобы сгенерировать для меня код, который я затем могу выполнить как отдельные тестовые примеры.
Попробуйте тестовые примеры, управляемые данными Расширение NUnit.