From 62e189bf846143b6baefcc0cec8e316e824abd69 Mon Sep 17 00:00:00 2001 From: "Henrik Sparre Spiegelhauer (HSPU)" Date: Fri, 15 Mar 2024 09:05:14 +0100 Subject: [PATCH] Adds junit as reporter --- tests/testthat.R | 2 +- tests/testthat/binary_type_2.R | 60 +++++++++++++++-------------- tests/testthat/test-binary_type_2.R | 3 -- vignettes/validation.Rmd | 1 - 4 files changed, 33 insertions(+), 33 deletions(-) diff --git a/tests/testthat.R b/tests/testthat.R index 7ac6f20..4bf755d 100644 --- a/tests/testthat.R +++ b/tests/testthat.R @@ -9,4 +9,4 @@ library(testthat) library(ramnog) -test_check("ramnog") +test_check("ramnog", reporter = JunitReporter$new(file = "junit_result.xml")) diff --git a/tests/testthat/binary_type_2.R b/tests/testthat/binary_type_2.R index 7ac42e7..ba3e643 100644 --- a/tests/testthat/binary_type_2.R +++ b/tests/testthat/binary_type_2.R @@ -2,19 +2,21 @@ test_that("Binary outcomes of type 2 work", { # SETUP ------------------------------------------------------------------- testr::create_local_project() - mk_ep_def <- function(){ - chef::mk_endpoint_str( - data_prepare = mk_adae, - pop_var = "SAFFL", - pop_value = "Y", - treatment_var = "TRT01A", - treatment_refval = "Xanomeline High Dose", - group_by = list(list(AESOC = c())), - stratify_by = list(c("AEDECOD")), - stat_by_strata_by_trt = list(chefStats::n_subj_event, - chefStats::n_event) - ) -} + mk_ep_def <- function() { + chef::mk_endpoint_str( + data_prepare = mk_adae, + pop_var = "SAFFL", + pop_value = "Y", + treatment_var = "TRT01A", + treatment_refval = "Xanomeline High Dose", + group_by = list(list(AESOC = c())), + stratify_by = list(c("AEDECOD")), + stat_by_strata_by_trt = list( + chefStats::n_subj_event, + chefStats::n_event + ) + ) + } chef::use_chef( pipeline_dir = "pipeline", r_functions_dir = "R/", @@ -23,32 +25,34 @@ test_that("Binary outcomes of type 2 work", { mk_adam_fn = list(mk_adae), ) # ACT --------------------------------------------------------------------- - browser() targets::tar_make() targets::tar_load(ep_stat) # EXPECT ------------------------------------------------------------------ actual <- - tidyr::unnest(ep_stat[grepl("GASTRO", endpoint_group_filter) | - grepl("CARDIAC", endpoint_group_filter), - .(endpoint_group_filter, - stat_filter, - stat_empty, - fn_name, - stat_result)], cols = stat_result) |> + tidyr::unnest(ep_stat[ + grepl("GASTRO", endpoint_group_filter) | + grepl("CARDIAC", endpoint_group_filter), + .( + endpoint_group_filter, + stat_filter, + stat_empty, + fn_name, + stat_result + ) + ], cols = stat_result) |> setDT() |> setorder(-value) x <- mk_adae() n <- x[AESOC == "CARDIAC DISORDERS" & - AEDECOD == "SINUS BRADYCARDIA" & TRT01A == "Xanomeline High Dose"] |> uniqueN(by="USUBJID") + AEDECOD == "SINUS BRADYCARDIA" & TRT01A == "Xanomeline High Dose"] |> uniqueN(by = "USUBJID") E <- x[AESOC == "CARDIAC DISORDERS" & - AEDECOD == "SINUS BRADYCARDIA" & TRT01A == "Xanomeline High Dose"] |> nrow() + AEDECOD == "SINUS BRADYCARDIA" & TRT01A == "Xanomeline High Dose"] |> nrow() actual_values <- actual[grepl("CARDIAC", endpoint_group_filter) & - grepl("SINUS BRADYCARDIA", stat_filter) & - grepl("Xan", stat_filter)&(label == "n" | - label == "E")][order(label)][,value] -expect_equal(actual_values, c(E, n)) - + grepl("SINUS BRADYCARDIA", stat_filter) & + grepl("Xan", stat_filter) & (label == "n" | + label == "E")][order(label)][, value] + expect_equal(actual_values, c(E, n)) }) diff --git a/tests/testthat/test-binary_type_2.R b/tests/testthat/test-binary_type_2.R index e340007..d1787d3 100644 --- a/tests/testthat/test-binary_type_2.R +++ b/tests/testthat/test-binary_type_2.R @@ -13,7 +13,6 @@ test_that("multiplication works", { stratify_by = list(c("AEDECOD")), stat_by_strata_by_trt = list(chefStats::p_subj_event) ) - } @@ -27,6 +26,4 @@ test_that("multiplication works", { # ACT --------------------------------------------------------------------- targets::tar_make() targets::tar_load(ep_stat) - browser() - }) diff --git a/vignettes/validation.Rmd b/vignettes/validation.Rmd index dd84668..c0b4008 100644 --- a/vignettes/validation.Rmd +++ b/vignettes/validation.Rmd @@ -87,7 +87,6 @@ test_that("Valide stats when one strata level is not found", targets::tar_make() targets::tar_load(ep_stat) # EXPECT ------------------------------------------------------------------ - browser() x <- mk_adae_demo() # Relative Risk actual <-